[Unit]
Description=captive portal automation
[Service]
Type=simple
ExecStart=/usr/bin/python /home/pi/do.py
Restart=on-failure
RestartSec=5
The above is the content of a systemd service called caportal.service
running on an Ubuntu 14.04 machine. I need to repeat the service for every 30 minutes. How can i do that ?
/home/pi/do.py
import requests,json
import netifaces as ni
import commands as cm
gateway=ni.gateways()['default'][ni.AF_INET][0]
IPaddr=ni.ifaddresses('wlan0')[ni.AF_INET][0]['addr']
mac=ni.ifaddresses('wlan0')[ni.AF_LINK][0]['addr'].upper().replace(':','-')
ssid=cm.getoutput('iwgetid -r')
Home="http://"+gateway+":8010/"
URL=Home+"login.html"
print URL
d={}
d['IdSession']=mac
d['Language']='English'
d['refrescar']='0'
d['ip']=IPaddr
d['mac']=mac
d['DSP']=Home
d['AC']='1'
d['userlog']='vishnu'
d['userpass']='12345'
d['read']='checkbox'
d['Login']='+++Go+++'
try:
if ssid=='machCochin':
r=requests.post(URL,data=d)
print r.status_code
#raise ValueError("ERROR simulated")
else:
print "network is not machCochin"
except Exception as e:
pass