Hi, I am trying to write a program in perl. it is to check socket from my local machine to multiple remote machines, to multiple destinations. The limitation i have is, on my local machine i only have standard modules installed. I am using expect to skip password as well
1. source hosts list
abc.com
def.com
ghi.com
2. destination list contains host and port as a cvs file
123.com,1586
456.com,1234
789.com,5678
these files should be passed as argument , my program is still incomplete without expect. any help would be greatly appreciated
Please help, it is urgent, any help would be greatly appreciated. I am very new to perl. Kindly assist on completing this
#!/usr/bin/perl -w
use Data::Dumper;
use Expect;
use strict;
use warnings;
my $exp = new Expect;
$exp->log_file("SSHLOGFILE.txt");
$exp->log_stdout(0);
my $user = 'xxxxxx';
my $pw = 'yyyyyyyy';
if( ! defined $ARGV[0] ) {
print "Usage: new.pl source destination\n";
exit;
}
my $file1 = $ARGV[0] or die "Need to get CSV file on the command line\
+n";
my $file2 = $ARGV[1] or die "Need to get CSV file on the command line\
+n";
open my $info, $file1 or die "Could not open $file1: $!";
while( my $line = <$info>) {
print $line;
open(SSH,"/usr/bin/ssh xxxxxx\@host ps aux |") or die "$!\n";
open my $data, $file2 or die "Could not open $file2: $!";
for (my $nice = <$data>) {
chomp ($nice);
my ($servername, $portnumber) = split (',', $nice);
print "$servername \n";
print "$portnumber \n";
while (<SSH>) {
printf "%s %s\n", $servername, $portnumber;
use IO::Socket;
my $sock = new IO::Socket::INET (PeerAddr => $servername,P
+eerPort => $portnumber,Proto => 'tcp');
print "ERROR: Could not create socket: $!\n" unless $sock
+;
printf "%s\n", "SUCCESS: Port Responded" if $sock;
close($sock) if $sock;
}
close SSH;
exit;
redo;
}
close $data;
}
close $info;
exit