[Tutor] help with subprocess module
Peter Otten
__peter__ at web.de
Sat Aug 19 14:29:45 EDT 2017
kay Cee wrote:
> 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'])
Hm, are you sure you want to reboot here?
>
>
> except UpdateError:
>
> print("Update Error!!!")
>
>
> update_log.close()
>
>
> if __name__ == '__main__':
>
> update()
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list