forked from rc2sql/rc2sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.sh
executable file
·159 lines (143 loc) · 3.3 KB
/
functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
function run() {
if [[ "${skip}" == "1" ]]
then
echo -n "TO"
return 0
fi
local cmd="${1}"
local ts1="$(date +%s%N)"
timeout ${to} script /dev/null </dev/null -eqc "${cmd}" &> /dev/null
local status="${?}"
local ts2="$(date +%s%N)"
local delta="$((ts2 - ts1))"
local t="$(echo "scale=1; ${delta}/1000000000" | bc -l)"
if [[ "${status}" == "0" && "$(echo "${t} < ${to}" | bc -l)" == "1" ]]; then
printf "%.2f s" "${t}"
ts+=("${t}")
elif [[ "${status}" == "124" || "$(echo "${t} >= ${to}" | bc -l)" == "1" ]]; then
echo -n "TO"
skip=1
else
echo -n "RE"
fi
}
function runNoTO() {
local cmd="${1}"
local ts1="$(date +%s%N)"
bash -c "${cmd}" &> /dev/null
local status="${?}"
local ts2="$(date +%s%N)"
local delta="$((ts2 - ts1))"
local t="$(echo "scale=1; ${delta}/1000000000" | bc -l)"
if [[ "${status}" == "0" ]]; then
printf "%.2f s" "${t}"
else
echo -n "RE"
fi
}
function init() {
echo -n "&"
runNoTO "./src/rtrans.native z_${i}"
./src/vgtrans.native "z_${i}"
./src/fo2reg.native "z_${i}"
symlinks "${prefix}/z_${i}"
./radb.sh "z_${i}"
}
function killPSQL() {
x="$(psql < /dev/null 2>&1)"
while [[ "$(echo "${x}" | grep -o "FATAL")" != "" ]]
do
sleep 1
x="$(psql < /dev/null 2>&1)"
done
cmd="SELECT pid FROM pg_stat_activity WHERE state = 'active' AND query NOT LIKE '%pg_stat%';"
pids="$(echo ${cmd} | psql | grep -o '^ *[0-9]* *$')"
for i in ${pids}
do
echo "SELECT pg_terminate_backend(${i});" | psql &> /dev/null
done
}
function killMSQL() {
while [[ 1 ]]
do
kil=$(mysql -h 127.0.0.1 -P 3306 -u rcsql -e "SELECT id FROM information_schema.processlist WHERE db = 'db';" -ss | awk '{print "KILL "$1";"}')
if [[ "${kil}" == "" ]]
then
break
fi
echo ${kil} | mysql -h 127.0.0.1 -P 3306 -u rcsql &> /dev/null
done
}
function checkstat() {
msg="${1}"
if [ "${status}" -ne 0 ]
then
if [ "${status}" -eq 124 ]
then
echo "TO: ${pref}/${msg}" >> log.txt
elif [ "${status}" -ne 0 ]
then
echo "RE: ${pref}/${msg}" >> log.txt
sleep 10
fi
fi
}
function symlinks() {
pref="${1}"
ln -sf "${pref}.sig" "${pref}.ssig"
ln -sf "${pref}.sig" "${pref}.asig"
ln -sf "${pref}.log" "${pref}.slog"
ln -sf "${pref}.log" "${pref}.alog"
ln -sf "${pref}.sig" "${pref}.vssig"
ln -sf "${pref}.sig" "${pref}.vasig"
ln -sf "${pref}.log" "${pref}.vslog"
ln -sf "${pref}.log" "${pref}.valog"
}
function run01SPSQL() {
run "psql < z_${i}.psql; ./run_psql.sh z_${i}.s"
killPSQL
}
function run01APSQL() {
run "psql < z_${i}.psql; ./run_psql.sh z_${i}.a"
killPSQL
}
function run02SPSQL() {
if [[ -f z_${i}.vsfin ]]
then
run "psql < z_${i}.psql; ./run_psql.sh z_${i}.vs"
killPSQL
else
echo -n "\\vgtna"
fi
}
function run02APSQL() {
if [[ -f z_${i}.vafin ]]
then
run "psql < z_${i}.psql; ./run_psql.sh z_${i}.va"
killPSQL
else
echo -n "\\vgtna"
fi
}
function run03() {
run "./ailamazyan/src/ail.native -fmla z_${i}.fo -db z_${i}.db"
}
function run04DDD() {
run "./ddd-rc/ddd z_${i}.fo z_${i}.db"
}
function run04LDD() {
run "./ldd-rc/ldd z_${i}.fo z_${i}.db"
}
function run05() {
run "./mpreg.sh z_${i}"
}
function line() {
echo -n "${1}"
for i in ${seeds}
do
skip=0
echo -n "&"
${2} ${i}
done
echo "\\\\"
}