-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetstat
104 lines (92 loc) · 2.92 KB
/
getstat
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
#xShellz API & PHP callbacks written by StephenS <-> [email protected]
#getstat bash script written by bolt <-> [email protected]
#!/usr/bin/env bash
_scriptname="getstat"
set -u
set -e
ftphost="edithost.com"
ftpuser="edituser"
ftppass="editpass"
ok="statusok.gif"
warn="statuswarning.gif"
fail="statusfailed.gif"
srvhost="/home/xinfo/srvstat/srvhost"
srvip="/home/xinfo/srvstat/srvip"
srvstat="/home/xinfo/srvstat/srvstat"
srvphp="/home/xinfo/srvstat/index.php"
source /cathedral/src/lib/shellfunc
function cleanup
{
set +e
sf_rm_process
}
trap cleanup EXIT
sf_mkfile -qo newstat
function check
{
local target=$1 port=$2
echo -n "CHECK: ${target}:${port}..."
if output=$(/cathedral/userbin/ussh -n -o BatchMode=yes -o ConnectTimeout=20 "bolt@$target" -p $port "uptime" 2>/dev/null); then
read -r output <<<"$output"
echo "$output" >>"$newstat"
output=${output#*up }
output=${output%user*}
output=${output%,*}
echo " OK"
return 0
else
echo " FAIL"
return 1
fi
}
sf_mkfile -qo newphp
sf_mkfile -qo newip
function readtab
{
local varname=$1 linename=$2
local line=${!linename}
local var="${line%%$'\t'*}"
printf -v "$varname" "%s" "$var"
if [[ "$var" = "$line" ]]; then
line=""
else
read -r line <<<"${line#*$'\t'}"
fi
printf -v "$linename" "%s" "$line"
}
first=true
while read -r srv; do
readtab name srv
readtab host srv
readtab port srv
ip=$(sf_lookup "$host" | grep -v ":" | head -n 1)
if [[ -n "$ip" ]]; then
while read -r line; do
if [[ "${line%%$'\t'*}" = "$host" ]]; then
ip="${line##*$'\t'}"
break
fi
done <"$srvip"
fi
if [[ -n "$ip" ]]; then
echo -e "$host\t$ip" >>"$newip"
fi
if $first; then
first=false
else
echo -n ' <img src="/bolt/spacer.gif"> | ' >>"$newphp"
fi
if check "$host" "${port:-22}"; then
echo -en "$name: $host ($output) <img src=\"/bolt/${ok}\">" >>"$newphp"
elif [[ -n "$ip" ]] && check "$ip" "${port:-22}"; then
echo -en "$name: $host ($output) <img src=\"/bolt/${warn}\">" >>"$newphp"
else
echo -en "$name: $host <img src=\"/bolt/${fail}\">" >>"$newphp"
echo "Offline" >>"$newstat"
fi
done <"$srvhost"
cat "$newip" >"$srvip"
cat "$newstat" >"$srvstat"
cat "$newphp" >"$srvphp"
echo "UPLOAD: $ftphost"
/cathedral/userbin/shellfunc timeout 60 lftp -e "debug; set ftp:ssl-allow no; set ssl:verify-certificate no; put $srvphp; bye" -u "$ftpuser,$ftppass" "$ftphost" || echo "Upload failed"x