From: Salvador F. <sfa...@ya...> - 2011-02-01 17:17:43
|
----- Original Message ---- > From: ncmudbug <jam...@em...> > To: exp...@li... > Sent: Tue, February 1, 2011 1:01:48 AM > Subject: Re: [Expectperl-discuss] Debugging timeouts > > > Thanks, Roland. The ssh idea sounds intriguing. Maybe you can help me with > it. If the command fails, I would like to know why from stderr. In my > playing with it, I didn't get an error message. Is there a way around that? > Jim Jim, If you need to automate an SSH process, you should try first using some of the SSH modules available from CPAN, for instance Net::OpenSSH (I am its author ;-), Net::SSH2 (recommended in Windows environments) or Net::SSH::Expect (recommended if you need to talk to network equipment or anything not running an standard command shell). They would allow you to get return codes from the remote commands and capture its I/O streams with minimum hashle. For instance: use Net::OpenSSH '1.51_01'; use Net::OpenSSH::Constants 'OSSH_SLAVE_CMD_FAILED'; my $ssh = Net::OpenSSH->new($remotehost, timeout => 10, kill_ssh_on_timeout => 1); $ssh->error and die "Unable to connect to remote host: " . $ssh->error; $ssh->system(test => -d => "/media/tmp") or do { if ($ssh->error == OSSH_SLAVE_CMD_FAILED) { die "Remote command failed, rc=" . ($? << 8); } else { die "SSH failed: " . $ssh->error; } } |