I think what I want is straight forward.
Python script to restart my Raspberry Pi after 23 hours and 59 minutes. The reason I am trying to do this, instead of set times with a cron job, is the Pi has no onboard battery for a clock so I don't care what the time is (if connected to internet, it will source current time), just a count down of 23 hours and 59 minutes from the script starting.
This is as far as I have got;
def restart():
SendEmail = SendEmail "SYSTEM RESTART", "ncam.py auto restart initiated" msg['Subject'], body)
command = "/usr/bin/sudo /sbin/shutdown -r now"
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
Also I want to send an email to myself with the set parameters as above.
You are going to want some variant of this:
import time
import os
currentTime = time.time()
tomorrow = currentTime + 86340000
while time.time() < tomorrow:
do.yourCode()
os.system("poweroff")
Put something like that in your function and it will do what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With