Hi Neil,
Thanks for the response. I have modified the code accordingly. Still I am getting error. I am very new to perl
This is the error
*********
ERROR: Could not create socket: Invalid argument
Use of uninitialized value $servername in printf at ./new.pl line 42.
Use of uninitialized value $portnumber in printf at ./new.pl line 42.
**************
#!/usr/bin/perl -w
use Data::Dumper;
use Expect;
use strict;
use IO::Socket;
use warnings;
my $exp = new Expect;
$exp->log_file("SSHLOGFILE.txt");
$exp->log_stdout(0);
my $user = '*****';
my $pw = '**********';
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( my $ssh_fh, "|-", 'ssh xxxxx@yyyy ps aux |' )
or die " Could not ssh [$!]\n";
open( my $data_fh, ">", $file2 )
or die "Could not open [$file2] [$!]";
for (my $nice = <$data_fh>) {
chomp ($nice);
my ($servername, $portnumber) = split (',', $nice);
print "$servername \n";
print "$portnumber \n";
while ($ssh_fh) {
printf "%s %s\n", $servername, $portnumber;
my $sock = new IO::Socket::INET (PeerAddr => $
+servername,PeerPort => $portnumber,Proto => 'tcp');
print "ERROR: Could not create socket: $!\n"
+unless $sock;
printf "%s\n", "SUCCESS: Port Responded" if $s
+ock;
close($sock) if $sock;
}
close $ssh_fh;
exit;
redo;
}
close $data_fh;
}
close $info;
exit
|