Gradian has asked for the wisdom of the Perl Monks concerning the following question:
Any suggestions would help. I'm running in circles with this and have tried a few different things with no success. Thank in advance guys.#!/usr/bin/perl -w use strict; use Net::Ping; use Net::SSH::Expect; use IO::Prompt; use Term::ReadKey; $|=1; #flushes IO Writehandle my $passwd = prompt("Please enter password:", -e => '*'); my $passwd1 = prompt("Please enter second password:", -e => '*'); open (HOSTS, "host_list") or die "can't find it! $!\n"; my @lines =<HOSTS>; foreach my $line(@lines){ chomp($line); my $p = Net::Ping->new("icmp"); unless($p->ping($line)){ print "$line <-- is unreachable please investig +ate \n"; }else { &log_in($line,$passwd,$passwd1); } $p->close(); } close (HOSTS); sub log_in{ my $timeout = 1; my $cmd = 'dmidecode | grep -A 4 "System Information" | grep -A 3 "Pro +duct Name:"'; my $cmd = 'ls -al'; my ($line,$passwd,$passwd1) = @_; #Create expect object and spawn; my $exp = new Expect() or die "Cannot spawn ssh command\n"; $exp->raw_pty(0); #$exp->log_file ("output.log", "w"); $exp->spawn("ssh -l root $line") or die "Invalid data passed t +o server... $!\n"; $exp->expect($timeout, ["[Tt]he" => sub {$_[0]->send("yes\n"); +}]); $exp->expect($timeout, ["[Pp]assword" => sub { $_[0]->send("$p +asswd\n"); }]); $exp->expect($timeout, ["[Pp]ermission" => sub {$_[0]->send("$ +passwd1\n");}]); $exp->expect($timeout, [ "[Rr]oot" => sub { $_[0]->send("$cmd\ +n"); } ]); #sleep 2; $exp->expect($timeout, [ "prompt-string" => sub { $_[0]->send( +"exit\n"); } ]); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Expect script to pull data from multiple servers...
by almut (Canon) on Nov 18, 2008 at 23:49 UTC | |
|
Re: Expect script to pull data from multiple servers...
by ig (Vicar) on Nov 19, 2008 at 03:29 UTC | |
by Gradian (Initiate) on Nov 19, 2008 at 14:58 UTC |