-
Notifications
You must be signed in to change notification settings - Fork 2
/
maintenance.sh.sample
38 lines (31 loc) · 1.26 KB
/
maintenance.sh.sample
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
#!/bin/bash
# Start OLED display script with timeout argument of 10min (600s)
#if ! (ps -ef | grep -q "[m]id.py") ; then
# # Display is currently free
# ((python /home/mid/oled-i2c/maintenance.py && python /home/mid/oled-i2c/mid.py 600) &)
#else
# # Display is currently busy, kill it first
# ps -ef | grep "[m]id.py" | awk '{print "kill -9", $2}' | sh ; ((python /home/mid/oled-i2c/maintenance.py && python /home/mid/oled-i2c/mid.py 600) &)
#fi
# Get unique number from hostname such as 'mobileid001' -> id=001
id=$(hostname | cut -c 9-11)
re='^[0-9]+$'
# Test if id is a number. If not, use id 000 instead
if ! [[ $id =~ $re ]] ; then
id=000
fi
ifconfig eth0 down
sleep 10
route add default ppp0
# Start PPP interface (LTE modem connectivity)
# wrapper script for wvdial to auto-reconnect in case connection is dropped randomly
(
while : ; do
sudo wvdial > /dev/null 2>&1
sleep 30
done
) &
sleep 10
# Start AutoSSH reverse-tunnel to a remote server
# Once the tunnel has been established, you can remote SSH to the Pi: $ ssh -i ~/.ssh/id_rsa mid@localhost -p 19<id>
(autossh -M 0 -o "ExitOnForwardFailure=yes" -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -fN -R 19"$id":localhost:22 -i /root/.ssh/id_rsa mid@<server-addr> -p 22) &