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()
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to