-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_bot.sh
More file actions
executable file
·37 lines (30 loc) · 954 Bytes
/
run_bot.sh
File metadata and controls
executable file
·37 lines (30 loc) · 954 Bytes
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
#!/bin/bash
# Source: https://askubuntu.com/questions/3299/how-to-run-cron-job-when-network-is-up
function check_online
{
netcat -z -w 5 8.8.8.8 53 && echo 1 || echo 0
}
# How many times we should check if we're online - this prevents infinite looping
MAX_FAILURES=10
# Initial starting value for checks
PING_FAILURES=0
# Loop while we're not online.
IS_ONLINE=$(check_online)
while [ $IS_ONLINE -eq 0 ]; do
# We're offline. Sleep for a bit, then check again
sleep 10;
IS_ONLINE=$(check_online)
PING_FAILURES=$[ $PING_FAILURES + 1 ]
if [ $PING_FAILURES -gt $MAX_FAILURES ]; then
break
fi
done
if [ $IS_ONLINE -eq 0 ]; then
# We never were able to get online. Kill script.
echo "run_bot.sh failed, could not detect a network connection"
exit 1
fi
# Start the bot
(cd /root/RealTimeBot && python3 RealTimeBot.py) &
echo "run_bot.sh succeeded, bot has been initialized"
ps -aux | grep "RealTimeBot.py"