Re: [Tutor] Better way to check *nix remote file age?
Hi, I would recommend you to migrate your Python version for a newer one where you can use fabric, paramiko or other ssh tools. It would be easier. I would recommend also instead of doing an ls -l command doing something to retrieve only the information you need: /bin/ls -ls | awk '{print $7,$8,$9, $10}' Jun 27 10:36 my_file Then I would use timedelta instead where you can be more accurate with the dates (in the example if the file is older than 62 days): def too_old(text): month, day, year = (text[0], text[1], text[2] if ':' not in text[2] else datetime.datetime.now().year) time_difference = datetime.datetime.now() - datetime.datetime.strptime( {0}{1}{2}.format(month, day, year), '%b%d%Y') return time_difference datetime.timedelta(days=62) Thanks, Raúl On Thu, Jun 26, 2014 at 7:40 PM, Albert-Jan Roskam fo...@yahoo.com.dmarc.invalid wrote: snip 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 Interesting. Question: what is the added value of paramiko compared to using subprocess to use ssh (ie, shell commands)? (Possible answer: it is platform-independent) Regards, Albert-Jan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor -- Raúl Cumplido ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to check *nix remote file age?
Raúl Cumplido, 27.06.2014 12:10: I would recommend you to migrate your Python version for a newer one where you can use fabric, paramiko or other ssh tools. It would be easier. +1 Even compiling it yourself shouldn't be too difficult on Linux. I would recommend also instead of doing an ls -l command doing something to retrieve only the information you need: /bin/ls -ls | awk '{print $7,$8,$9, $10}' Jun 27 10:36 my_file Or run some Python code on the other side, e.g. with python -c 'python code here' Stefan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to check *nix remote file age?
Hi, On 26 June 2014 19:40, Albert-Jan Roskam fo...@yahoo.com wrote: snip 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 Interesting. Question: what is the added value of paramiko compared to using subprocess to use ssh (ie, shell commands)? (Possible answer: it is platform-independent) Parsing command line output is arguably generally (more) brittle and prone to breakage than coding to a direct API/library -- Paramiko friends give you a proper programming API to code against with direct/native access to object properties. A file modification date and time (for example) from a shell command command is a string that then must be parsed/interpreted. This might be subject to locale format, command/shell settings and who knows what else. By contrast a stat result is a more well defined entity with unambiguous contents, completely removing having to guess/parse text. IMVHO much more preferable. :) Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to check *nix remote file age?
On Fri, Jun 27, 2014 at 7:41 AM, Stefan Behnel stefan...@behnel.de wrote: Raúl Cumplido, 27.06.2014 12:10: I would recommend you to migrate your Python version for a newer one where you can use fabric, paramiko or other ssh tools. It would be easier. +1 Even compiling it yourself shouldn't be too difficult on Linux. I'm not retro just for the heck of it. There's no reason to avoid Python 3.x but sometimes you just have to work with what you have. Anyone willing to provide a couple million dollars and 12-18 months of free 24/7/365.25 support? I have to work with four different operating systems and three of the four have two versions. Most might have python installed but some don't. My code has to be clean enough that people new to Python can understand it when something goes south. Somewhat sorry for the rant. I just get tired of people saying upgrade when that's not an option. Leam -- Mind on a Mission http://leamhall.blogspot.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to check *nix remote file age?
Hi, On 27 June 2014 12:57, leam hall leamh...@gmail.com wrote: On Fri, Jun 27, 2014 at 7:41 AM, Stefan Behnel stefan...@behnel.de wrote: Raúl Cumplido, 27.06.2014 12:10: I would recommend you to migrate your Python version for a newer one where you can use fabric, paramiko or other ssh tools. It would be easier. +1 Even compiling it yourself shouldn't be too difficult on Linux. I'm not retro just for the heck of it. There's no reason to avoid Python 3.x but sometimes you just have to work with what you have. I presume you meant this 3.x reference above in a hyperbolic sense e.g. as to mean I absolutely can't upgrade the Python version I'm working with, at all. Nonetheless, I'd like to just point out, that at one place I work at one of the servers is also still using Python 2.5.4 with Paramiko without any problems -- so even a small version upgrade from where you're at might be enough to enable you to use things you currently cannot. I realise that even this might be impossible for you though. In such a case, (and apologies again if you already know this and it's not relevant) it's still often possible to have multiple versions of Python installed in a system, even if just in a user context/account and/or using something like virtualenv so as to leave the system wide installation untouched. E.g. just because an operating system has an old version of Python installed that absolutely cannot be touched, this doesn't necessarily mean that a user of the system cannot then have their own set of application binaries (including a newer version of Python) installed and use that instead of the system binaries to get their job done. (Again, I'm sure you know this already, so apologies if I'm telling you what you already know and am not helping here.) Anyone willing to provide a couple million dollars and 12-18 months of free 24/7/365.25 support? I have to work with four different operating systems and three of the four have two versions. Most might have python installed but some don't. I'm seriously not clear how these comments related to your question: In your original post you talked about a local server and a remote server, stating that you wanted the local server (with Python) to contact a remote server.. How does these 4 operating systems you mention factor into your original question? Only the local server needs Python. The remote only needs SSH. My code has to be clean enough that people new to Python can understand it when something goes south. Fair enough. Somewhat sorry for the rant. I just get tired of people saying upgrade when that's not an option. Fair enough again. Perhaps try be a bit more explicit about such non-negotiable constraints in future. While you mentioned a Python version in your original question, it wasn't really obvious as being a constraint and I certainly didn't interpret it as such. Best wishes, Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to check *nix remote file age?
Hi, On 26 June 2014 18:01, leam hall leamh...@gmail.com wrote: On Thu, Jun 26, 2014 at 12:41 PM, Walter Prins wpr...@gmail.com wrote: On 26 June 2014 14:39, leam hall leamh...@gmail.com wrote: Python 2.4.3 Is there a better way to do this? I'd probably rather try Paramiko's SFTPClient and retrieve the file Seem to not work on Python 2.4.3. What exactly did you try, and what error/output did you get? (I've had another look at Paramiko's homepage and it seems to support back to Python 2.2? [http://www.lag.net/paramiko/ ]) Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to check *nix remote file age?
On 06/27/14 17:40, Walter Prins wrote: Hi, On 26 June 2014 18:01, leam hall leamh...@gmail.com wrote: On Thu, Jun 26, 2014 at 12:41 PM, Walter Prins wpr...@gmail.com wrote: On 26 June 2014 14:39, leam hall leamh...@gmail.com wrote: Python 2.4.3 Is there a better way to do this? I'd probably rather try Paramiko's SFTPClient and retrieve the file Seem to not work on Python 2.4.3. What exactly did you try, and what error/output did you get? (I've had another look at Paramiko's homepage and it seems to support back to Python 2.2? [http://www.lag.net/paramiko/ ]) Walter Walter, I was cranky. Sorry. When I looked at ( http://www.paramiko.org ) it specified Python 2.6+ and 3.3+. That's echoed in the README ( https://github.com/paramiko/paramiko/blob/master/README ) I have not actually tested to see what breaks on a 2.4 box. The other option was to copy in the files and stat them. Trying to build a script that can be extended and not hit so much network bandwidth. The good thing about the way this is currently going is that a co-worker gave me a better Solaris solution that let me standardize the script for both Red Hat Linux and Solaris. Still need to figure out AIX. The possibility exists to build a python outside of the standard. The issue is supportability. Like many others I'm a contractor and need to make sure whatever I do is so boringly simple that I can train my replacement. On one hand, that's a good thing. If people use my scripts after I'm gone then hopefully they won't cuss too much. Since my exciting plans for the weekend have been canned I'll take a little time and think about how best to do this. Some of it is what should I do with my career type thinking. Some is just hey, how does this work?. Thanks for not responding as poorly as I did. Leam -- http://31challenge.net http://31challenge.net/insight ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to check *nix remote file age?
On 06/27/14 06:10, Raúl Cumplido wrote: Hi, I would recommend also instead of doing an ls -l command doing something to retrieve only the information you need: /bin/ls -ls | awk '{print $7,$8,$9, $10}' Jun 27 10:36 my_file Then I would use timedelta instead where you can be more accurate with the dates (in the example if the file is older than 62 days): def too_old(text): month, day, year = (text[0], text[1], text[2] if ':' not in text[2] else datetime.datetime.now().year) time_difference = datetime.datetime.now() - datetime.datetime.strptime( {0}{1}{2}.format(month, day, year), '%b%d%Y') return time_difference datetime.timedelta(days=62) Raúl, that looks interesting. Let me think through it. Leam -- http://31challenge.net http://31challenge.net/insight ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to check *nix remote file age?
Hi again ^^ On 27 June 2014 23:20, Leam Hall leamh...@gmail.com wrote: On 06/27/14 17:40, Walter Prins wrote: On 26 June 2014 18:01, leam hall leamh...@gmail.com wrote: On Thu, Jun 26, 2014 at 12:41 PM, Walter Prins wpr...@gmail.com wrote: On 26 June 2014 14:39, leam hall leamh...@gmail.com wrote: Python 2.4.3 Is there a better way to do this? I'd probably rather try Paramiko's SFTPClient and retrieve the file Seem to not work on Python 2.4.3. What exactly did you try, and what error/output did you get? (I've had another look at Paramiko's homepage and it seems to support back to Python 2.2? [http://www.lag.net/paramiko/ ]) Walter, I was cranky. Sorry. Not a problem, know the feeling. :) When I looked at ( http://www.paramiko.org ) it specified Python 2.6+ and 3.3+. That's echoed in the README ( https://github.com/paramiko/paramiko/blob/master/README ) I have not actually tested to see what breaks on a 2.4 box. Hmmm... OK. Interesting. Perhaps Paramiko head doesn't support it anymore on head in github... but it might still be possible to get an older version for Python 2.4, but I guess (having read the rest of your post already) that maybe this is not the best course of action for your situation -- I'll stop pushing this idea shortly, I promise! Nevertheless, continuing on... The other option was to copy in the files and stat them. Trying to build a script that can be extended and not hit so much network bandwidth. OK -- just to note, I think perhaps another small misunderstanding has slipped in somewhere. My suggestion isn't to actually retrieve the file *contents*, but rather to retrieve information *about* the file on the remote system. That means only the remote stats about the file travel over the wire, not the file contents itself. Hence it should be approximate as light, or lighter (give or take) than running an ssh command and retrieving the output I'd guess. The good thing about the way this is currently going is that a co-worker gave me a better Solaris solution that let me standardize the script for both Red Hat Linux and Solaris. Still need to figure out AIX. OK, I get that would be attractive for your use case. :) The possibility exists to build a python outside of the standard. The issue is supportability. Like many others I'm a contractor and need to make sure whatever I do is so boringly simple that I can train my replacement. On one hand, that's a good thing. If people use my scripts after I'm gone then hopefully they won't cuss too much. I get that as well. (A big complicated custom Python + Paramiko install is rather not the simplest/most maintainable solution when all you want is to know if a given file is of a certain age... especially if the in-house Python knowledge is limited and you need to hand it over to in-house staff.) Since my exciting plans for the weekend have been canned I'll take a little time and think about how best to do this. Some of it is what should I do with my career type thinking. Some is just hey, how does this work?. Good luck... need to do some of the same sometime (e.g. what should I do with my career), but I digress. :) Thanks for not responding as poorly as I did. No worries, hope you have a good weekend despite your plans being canned. Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Better way to check *nix remote file age?
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 users105 Jun 19 13:57 guido2 Old file: -rw--- 1 sam users105 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/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to check *nix remote file age?
On 26 June 2014 14:39, leam hall leamh...@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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to check *nix remote file age?
On Thu, Jun 26, 2014 at 12:41 PM, Walter Prins wpr...@gmail.com wrote: On 26 June 2014 14:39, leam hall leamh...@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 Seem to not work on Python 2.4.3. -- Mind on a Mission http://leamhall.blogspot.com/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better way to check *nix remote file age?
snip 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 Interesting. Question: what is the added value of paramiko compared to using subprocess to use ssh (ie, shell commands)? (Possible answer: it is platform-independent) Regards, Albert-Jan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor