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"); ... }