timeouts for Net::SSH::W32Perl

yishayjobs_at_hotmail.com
Date: 01/27/05

  • Next message: Brian McCauley: "Re: GD::Graph isn't numeric etc."
    Date: 27 Jan 2005 01:23:45 -0800
    
    

    To anyone interested,

    I've been trying to find an effective way for dealing with
    Net::SSH::W32Perl command timeouts. The 'timeout' issue can be defined
    thus: "How can I make sure my perl script does not hang after sending a
    remote ssh command?". For example:

    my ($out, $err, $exit) = $ssh->cmd("./startSomeScript.sh");
    # this should be executed next unless ssh cmd never returns

    I've come up with 3 approaches, none of which are flawless.

    1) use perl's alarm signal implementation (e.g.

    alarm $timeout;
    # some code
    my ($out, $err, $exit) = $ssh->cmd("./startSomeScript.sh");
    # some code
    alarm 0;
    # now carry on

    The results for this have not been consistent. Depending on $timeout
    command sometimes returns and sometimes doesn't. I'm not clear on
    whether alarm mechanism is considered stable on windows (I'm using
    ActiveState's 5.8.4 on XP and 2K). So I haven't investigated this much
    further (hence the annoying '# some code' in example).

    2) run remote process in background (e.g.

    my ($out, $err, $exit) = $ssh->cmd("./startSomeScript.sh &");
    # now carry on

    In theory ssh cmd should return immediately, in practice there are
    several conditions. One condition seems to be that file descriptors
    opened by cmd are closed. This is not always easy to insure.

    3) use perl's fork() implementation for windows (e.g.
    unless (my $pid = fork() ) {
    # make sure process process is stuck for consistent behavior
    while (1) {}
    } else {
    my ($out, $err, $exit) = $ssh->cmd("./startSomeScript.sh");
    my $time1 = time();
    while (time() - $time1 < $timeout)
    {
    sleep 1;
    }
    kill $pid;
    }
    # $ssh needs to be given a new instance otherwise behavior is
    unexpected
    $ssh = Net::SSH::W32Perl->new('host');
    $ssh->login('user', 'passwd');
    # resume control here

    This has proved the most effective approach so far. Unfortunately the
    script hangs after being repeated for long enough and we suspect this
    has to do with fork() overuse, although we may be wrong.

    So in essence what I'm looking for is a differnet approach for ssh
    timeouts which is not likely to have malicious side effects. We're
    using this for an automated testing framework, so I'd like to be able
    to repeat these commands for a day or more without having to worry
    about unexpected hangs.

    Any help would be much appreciated,
    Yishay


  • Next message: Brian McCauley: "Re: GD::Graph isn't numeric etc."

    Relevant Pages

    • Re: Really need help on this one
      ... Is there a way to read the output of a particular command into ... Heres a better example using ssh. ... set timeout $timeout ... exec kill -9 $pid ...
      (comp.lang.tcl)
    • Re: OT: Hard disk mirror with Paragon on USB stick?
      ... at least two pages of intricate command line stuff. ... The password is only used when you want to backup to a remote machine ... via the network, using the ssh protocol. ... (e.g. with linux, ...
      (sci.electronics.design)
    • RE: midnight commander and ssh sftp
      ... midnight commander and ssh sftp ... which is displayed at the bottom of the MC panel. ... "Left file command options right" at the top of the MC ... MC SSH session with the remote host by hitting F10 key. ...
      (freebsd-questions)
    • Re: sshd and ftpd
      ... ssh keys, so when you log in it doesn't ask for one. ... we want to be able to connect to our remote host without ... If you used the defaults supplied by the ssh-keygen command, ...
      (Ubuntu)
    • Re: ssh
      ... With 'fully' I mean that command: ... ssh target_machine_name date ... ~/.ssh/authorized_keys on my home computer. ... He also mentioned scp, and I think the better alternative would be to run sftp with a batch file. ...
      (Debian-User)