I'm wanting to run through each server, but if it gets to a server that it
can't login not to die. The "server-list.txt" has:
localhost
localhost2
localhost3
localhost4

When it gets to localhost3 and it dies with: Permission denied at ./
linux_discovery.pl line 20

I would like it to keep rolling over to localhost4, code below, open for
suggestions and appreciate it!

#!/usr/bin/perl -w
use Net::SSH::Perl;

my $file = "server-list.txt";
my $usr = "root";
my $pwd = "password";
my $output_file = "servers_information.txt";

open(HANDLE, $file) or die("Cant open the file :( ");
@server_list = <HANDLE>;
close(HANDLE);
chomp @server_list;

open(HANDLE, ">>$output_file");
foreach $host (@server_list)
{

my $ssh = Net::SSH::Perl->new($host);
print "Logging into server: $host \n";
$ssh->login($usr,$pwd,$ssh);
my($unameout) = $ssh->cmd("/bin/uname -a");
my($userout) = $ssh->cmd("/bin/cat /etc/passwd");
my($upout) = $ssh->cmd("/usr/bin/uptime");
my($lastout) = $ssh->cmd("/usr/bin/last");
my($ipout) = $ssh->cmd("/sbin/ifconfig");
my($hostout) = $ssh->cmd("/bin/hostname");
print HANDLE "---------------------------------- \n";
print HANDLE "Hostname : $host \n";
print HANDLE "Uptime : $upout \n";
print HANDLE "Kernel : $unameout \n";
print HANDLE "Users : $userout \n";
print HANDLE "Last Login : $lastout \n";
print HANDLE "IP Address : $ipout \n";
print HANDLE "Real Hostname: $hostout \n";
print HANDLE "----------------------------------\n\n";
}

Reply via email to