loops - Python script to continue running -
i new python programming. want code continue running , continue checking ip address. `
#!/usr/bin/env python import os hostname = "192.168.254.102" #example response = os.system("ping -c 1 " + hostname)
and check response...
if response == 0: print(hostname, 'is up!') os.system("sudo python ../aquarium/nightlight_on.py 1") else: print(hostname, 'is down!')
`
basically, cant code check phone ip address when got home script turn on light. tested script , works if run in terminal need sudo python scriptname.py first thank you
you use python schedule
open source project this:
#!/usr/bin/env python def job(): import os hostname = "192.168.254.102" #example response = os.system("ping -c 1 " + hostname) if response == 0: print(hostname, 'is up!') os.system("sudo python ../aquarium/nightlight_on.py 1") else: print(hostname, 'is down!') import schedule schedule.every(10).seconds.do(job)
and run python script background process unix &
flag:
$ sudo python yourscript.py &
you can install schedule pip
. still have restart process when computer reboots, or make upstart or systemd job handle that.
Comments
Post a Comment