From: Noah <ad...@en...> - 2008-06-10 15:58:18
|
Hi there, I am trying to log into multiple Devices via ssh. the first ssh sessions is handled fine. There is a for loop scrolling through IPs and the SSH session with the second IP in the list never gets open and the text is sent after the timeout. No prompts are ever seen. What am I doing wrong? Cheers, Noah #!/sw/bin/perl # # Unique Names script # Written by Noah Garrett Wallach # use Expect; # # # #--- ENSURE TO HAVE SUFFICIENT COMMAND LINE ARGUMENTS ! ----------------------# # if ( $#ARGV != 1 ) { printf("USAGE: $0 <user> <pw>\n"); exit(-1); } $user = shift; $pw = shift; $timeout = 10; my $infile = "ips.txt"; my $logfile = "it.txt"; &read_datafile; my $count = 0; foreach $host (@host) { &grab_config; $count++; } exit 0; sub grab_config { my $cmd = "ssh ${user}\@${host}"; my $exp = new Expect() || die "Cannot spawn ssh command \n"; $exp->log_file($logfile); $exp->raw_pty(0); $exp->spawn($cmd); $prompt = "$blah"; my $patidx = $exp->expect($timeout, [$prompt]); $exp->send("$pw\n"); $prompt = "$user\@\\w+\>"; $patidx = $exp->expect($timeout, [$prompt]); $exp->send("$blah\n"); $patidx = $exp->expect($timeout, [$prompt]); $exp->send("$blah\n"); $patidx = $exp->expect($timeout, [$prompt]); $exp->send("$blah\n"); $exp->soft_close(); } sub read_datafile { open(DATA,$infile) || die "unable to open $infile $! \n"; @host=<DATA>; close (DATA); } |