-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshellbotd.sh
executable file
·51 lines (43 loc) · 1.09 KB
/
shellbotd.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
#!/bin/bash
directory="$(dirname $(realpath $0))"
source $directory/config.sh
file='/tmp/shellbotd'
if [[ "$1" == 'stop' ]]; then
pkill shellbot
exit 0
fi
touch $file
if ! [[ -r $file ]]; then
echo "$file is unreadable!"
exit 2
fi
if ! [[ -w $file ]]; then
echo "$file is unwritable"
exit 3
fi
start_bot() {
$directory/shellbot.sh
}
[[ "$1" != "slave" ]] && {
echo "$$" > "$file"
$0 slave &
start_bot &
}
while true; do
[[ "$(cat "$file")" == "$$" ]] && {
ping -c1 api.telegram.org && {
(( "$(curl -s "$tele_url/getUpdates" | jq -r ".result | length")" >= 10 )) && {
pkill shellbot.sh
start_bot &
}
}
sleep 60
} || {
[[ $(ps aux | tr -s " " | cut -d " " -f 2 | grep -o "$(cat "$file")") ]] && {
sleep 5
} || {
echo "$$" > "$file"
$0 slave &
}
}
done