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

Walter Prins wprins at gmail.com
Thu Jun 26 18:41:30 CEST 2014


On 26 June 2014 14:39, leam hall <leamhall at gmail.com> wrote:
> 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?

I'd probably rather try Paramiko's SFTPClient and retrieve the file
modified date directly:
http://paramiko-docs.readthedocs.org/en/latest/api/sftp.html#paramiko.sftp_client.SFTPClient
(see the SFTPFile.stat() method in particular, which gives you back a
stat object containing mtime, the modification datetime IIRC)

2 more (hopefully) useful links if you decide to go this route:
http://www.saltycrane.com/blog/2010/02/python-paramiko-notes/
http://jessenoller.com/blog/2009/02/05/ssh-programming-with-paramiko-completely-different


Walter


More information about the Tutor mailing list