Add auto reboot router script
This commit is contained in:
parent
4ecfea6cfb
commit
4c19c89935
1 changed files with 40 additions and 0 deletions
40
routercheckandreboot.py
Normal file
40
routercheckandreboot.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os,time
|
||||
|
||||
# Get current WAN IP Address from router
|
||||
x = os.popen("ssh admin@192.168.10.254 ip addr show ppp0 | grep inet | awk '{print $2}'").read()
|
||||
|
||||
# Make output go through telegram-send in a container
|
||||
output = "podman run -it --rm -v /media/core/Data2/Apps/telegram-send/telegram-send.conf:/etc/telegram-send.conf tsend:20230108 telegram-send -g "
|
||||
|
||||
# Define current runs as 0
|
||||
y = 0
|
||||
|
||||
# Send current IPv4 WAN address to telegram-send
|
||||
os.system(output+"'IPv4 is "+x+"'")
|
||||
|
||||
# If xxx (as in xxx.yyy.yyy.yyy) is 100 or not starting with a number (such as error messages), reboot router. No more than 30 runs.
|
||||
while((x[:3] == "100" or (int(x[0]) not in [0,1,2,3,4,5,6,7,8,9])) and y < 30):
|
||||
os.system(output+"Rebooting..")
|
||||
os.system("ssh admin@192.168.10.254 reboot")
|
||||
time.sleep(200) # Give the router some time to reboot, currently 200 seconds.
|
||||
x = os.popen("ssh admin@192.168.10.254 ip addr show ppp0 | grep inet | awk '{print $2}'").read()
|
||||
os.system(output+"'Now IPv4 is "+x+"'")
|
||||
y += 1
|
||||
|
||||
# If IP does not start with 100, do nothing.
|
||||
if y==0:
|
||||
os.system(output+"'IPv4 does not start with 100, not rebooting.'")
|
||||
|
||||
# Reboot complete, now tell the user how many runs and finally restart the Syncthing relay.
|
||||
elif y < 30:
|
||||
os.system(output+"'yay :)'")
|
||||
os.system(output+"'Router has been rebooted "+str(y)+" time(s).'")
|
||||
os.system(output+"'Restarting Syncthing relay!'")
|
||||
os.system("systemctl --user restart syncthing-relay")
|
||||
|
||||
# Complain if 30 runs are not enough
|
||||
else:
|
||||
os.system(output+"'So Bad ;('")
|
||||
|
Loading…
Reference in a new issue