小编mcv*_*mcv的帖子

如何定期运行 systemd 服务?

[Unit]
Description=captive portal automation

[Service]
Type=simple

ExecStart=/usr/bin/python /home/pi/do.py
Restart=on-failure
RestartSec=5
Run Code Online (Sandbox Code Playgroud)

以上是caportal.service在Ubuntu 14.04机器上运行的一个名为systemd服务的内容。我需要每 30 分钟重复一次该服务。我怎样才能做到这一点 ?

/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
Run Code Online (Sandbox Code Playgroud)

scripts services systemd

2
推荐指数
1
解决办法
9313
查看次数

标签 统计

scripts ×1

services ×1

systemd ×1