hxbsy has asked for the wisdom of the Perl Monks concerning the following question:
hi,
I would run SSH by thread,but with error message `SSHConnectionAborted`.
if I run it in main,it runs well.
Can anybody please help me in this?
use Net::SSH::Expect; use Expect; use thread; my $thr=threads->new(\&job,$console,$username,$password,$timeout); $thr->join(); sub job{ my ($console,$username,$password) = @_ my $consoleprompt = 'yes\/no|assword|[\$#>\]]$|[\$#>\]] $|>.$|].$'; my $ssh = Net::SSH::Expect->new( host => $console, user => $username, password => $password, timeout => $timeout, log_file => "./log/$console", raw_pty => 1 ); my $ssh->run_ssh() or die "SSH process coundn't start:$!"; $ssh->waitfor($consoleprompt,15); my $match=$ssh->match(); if($match =~ /yes\/no/) { print "known_hosts_tables not existing the device"; $ssh->send("yes"); $ssh->waitfor('assword',5); $ssh->send("$password"); } elsif($match =~ /assword/) { $ssh->send("$password"); } $ssh->waitfor($consoleprompt,5); $ssh->send("sup"); ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SSH by thread
by BrowserUk (Patriarch) on May 14, 2015 at 10:03 UTC | |
by Anonymous Monk on May 14, 2015 at 19:51 UTC | |
|
Re: SSH by thread
by james28909 (Deacon) on May 14, 2015 at 05:38 UTC | |
by Happy-the-monk (Canon) on May 14, 2015 at 07:08 UTC | |
by SimonPratt (Friar) on May 14, 2015 at 09:36 UTC | |
by Happy-the-monk (Canon) on May 14, 2015 at 11:02 UTC | |
by james28909 (Deacon) on May 15, 2015 at 00:25 UTC |