How to telnet to other unix machines and grep log files etc?

Quinn Dunkan quinn at regurgitate.ugcs.caltech.edu
Wed Jul 25 13:29:21 EDT 2001


On 25 Jul 2001 17:22:12 GMT, Quinn Dunkan <quinn at regurgitate.ugcs.caltech.edu>
wrote:
>On 25 Jul 2001 08:42:44 -0700, Chris <bit_bucket5 at hotmail.com> wrote:
>>Relative unix newbie.  Would like to write a python script to do what
>>I do manually--telnet to two different unix machines from a third unix
>>machine.  Grep through some log files, gather the grep results from
>>the different machines and spit them out.  I think I need to do
>>something with popen, or popen2, or ???  I don't know where to start. 
>>Any pointers much appreciated.
>
>This is a shell task:
>
>(ssh machine1 'grep foo /sys/log/bar';
> ssh machine2 'grep baz /sys/log/faz') >results
>
>Create an RSA key with no passphrase if you don't want to have to type
>passwords all the time.

BTW, if you *really* wanted to use python for it, you couldn't use popen
(stdio wins again!).  You'd need to use ptys to trick telnet that it's being
run by a terminal.  That means either figuring out how unix ptys work and
using pty.py, or installing expect and ExpectPy.  Both are more work than
installing openssh (and once you do that you can toss telnet anyway).

Unless, of course, machine{1,2} don't have ssh and you have no control over
them.  There are any number of ugly hacks you could do at that point, and
expect is one of them.

or-publish-the-logs-on-the-web-and-use-wget-ly y'rs



More information about the Python-list mailing list