#!/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 =; foreach my $line(@lines){ chomp($line); my $p = Net::Ping->new("icmp"); unless($p->ping($line)){ print "$line <-- is unreachable please investigate \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 "Product 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 to server... $!\n"; $exp->expect($timeout, ["[Tt]he" => sub {$_[0]->send("yes\n");}]); $exp->expect($timeout, ["[Pp]assword" => sub { $_[0]->send("$passwd\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"); } ]); }