[Tutor] Better way to check *nix remote file age?

leam hall leamhall at gmail.com
Thu Jun 26 15:39:19 CEST 2014


Python 2.4.3

Writing a function that takes the string from "ssh <server> ls -l
/var/log/yum.log" and tries to see if the file is more than a couple months
old. The goal is to only run python on the local server and it will ssh
into the remote server.

Is there a better way to do this?

Thanks!

Leam

####

Standard type of string that would come in date_string:

New file:
  -rw-------  1 sam users    105 Jun 19 13:57 guido2

Old file:
  -rw-------  1 sam users    105 May 19 2011 guido



####

def linux_too_old(date_string):
        '''(string) -> boolean

        Returns True if the date string is more than a couple months old.

        '''

        months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
'Sep', 'Oct', 'Nov', 'Dec']
        this_month = datetime.date.today().month

        file_date = date_string.split()

        if ':' not in file_date[7]:
                return True

        file_month = file_date[5]

        if 0 < (this_month - months.index(file_month)) < 3:
                return False




-- 
Mind on a Mission <http://leamhall.blogspot.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140626/537c835b/attachment.html>


More information about the Tutor mailing list