[Tutor] help with subprocess module
kay Cee
unee0x at gmail.com
Sat Aug 19 06:13:48 EDT 2017
I made a python script that will update a Ubuntu Server every second and
writes asuccess message and date to a log file, but for some reason the
file is not being written to.
Here is the Script:
#!/usr/bin/python3
import subprocess
import time
import datetime
class UpdateError(Exception):
pass
def update():
while True:
try:
update_log = open('update_log.txt', 'r+')
time.sleep(1)
subprocess.call(['apt-get', 'update', '-y'])
date = datetime.datetime.now()
update_log.write("System was updated sucessfully on {}\n".format
(str(date)))
subprocess.call(['reboot'])
except UpdateError:
print("Update Error!!!")
update_log.close()
if __name__ == '__main__':
update()
More information about the Tutor
mailing list