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

Cameron Laird claird at starbase.neosoft.com
Wed Jul 25 15:13:20 EDT 2001


In article <slrn9lu0fg.vpg.quinn at regurgitate.ugcs.caltech.edu>,
Quinn Dunkan <quinn at regurgitate.ugcs.caltech.edu> wrote:
>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

Exactly.  That is, ssh is a fine way to solve these
problems--unless you don't have control over the re-
mote end.

Long term, ExpectPy might be in better shape than
you realize.  There are glimmers of hope that Expect
might be rewritten in a way that eases maintenance
of ExpectPy (and maybe brings Win* within range, too).
In the meantime, you might consider using stock Expect.
You might be able to get your job done with just a few
lines.  If you need more, there are plenty of ways to
tie together Tcl and Python codings.
-- 

Cameron Laird <claird at NeoSoft.com>
Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html



More information about the Python-list mailing list