timing out an ssh command

Dreico-Hyper-Dynamics dreico at wanadoo.fr
Thu May 8 15:41:08 EDT 2003


> > def the_command():
> >     payload = string.join(sys.argv[1:])
> >     sshcmd = 'ssh -1 -o StrictHostKeyChecking=no -l root ' + payload
>
> This almost certianly doesn't do what you want.  It runs the the first
> command listed on the command line with all the other commands sent as
> arguments.  Also, logging in remotely as root is often disabled.

Ah but it does ... at this time I'm no ssh expert, but the environment the
wrapper
exploits uses kerberos token forwarding which enables certain users to log
into
remote machines as root without entering a passwd. If I understand you
correctly, yes indeed the first command on the cmd line is the name of the
script: brush,
and the rest is the "payload", so in a normal situation:

prompt> ./brush target01 uptime
prompt> uptime output blah blah

is exactly the same as doing

prompt> ssh -l root target01 uptime
prompt> uptime output blah blah

and it does work ... however, as shown in my original posting, there are
situations
when

a) machine target01 is pingable, therefore it's possible to send the command

but

b) for some reason the process "chokes" when trying to talk to sshd at the
other end

Either way, situation (b) constitutes a hung process, which I would like to
kill after
a certain timeout period.

> As far as I can tell, your ssh process doesn't hang, it's just waiting
> for data, most likely a host key validation or a password, neither of
> which you handle.

True enough, but as I say, in a normal situation it works. I'm just trying
to
cover the abnormal situation.

> You didn't answer my original question either.  Why do you need to run
> multiple commands on a remote server in Python?  If you just want a
> simple command, 'ssh -l username host "command1; command2; command3"'
> should do the trick.

Well this is the whole point of the exercise =): a wrapper for the above
type of ssh command, but one which caters for

a) machines which cannot be contacted

and

b) machines which respond too slowly.

A.






More information about the Python-list mailing list