use strict; use warnings; use Data::Dumper; use feature 'say'; no warnings 'uninitialized'; my @fail; my @CLI; my $pass; my $mire; my @ip; my $ssh_cli = 'ssh -o StrictHostKeyChecking=no -o ConnectTimeout=3 -l'; print 'Login: '; chomp (my $login = <>); print 'Password: '; chomp (my $password = <>); print 'Fichier IP: '; chomp (my $SOURCE = <>); print 'Fichier ligne de commandes:'; chomp (my $commande = <>); open (my $source, "<", $SOURCE) or die "Can't open: $!"; while (my $line = <$source>) { $line =~ s/[\r\n]+//; push @ip, $line; } open (my $cli, "<", $commande) or die "Can't open: $!"; while (my $line = <$cli>) { $line =~ s/[\r\n]+//; push @CLI, $line; } foreach my $ip (@ip) { my $SSH = system "$ssh_cli $login $ip"; if ($SSH =~ /username/i) { my $pass = print "$login\n"; } else { say "Connexion SSH $ip echec"; push @fail, $ip; say '-' x 20; next; } if ($SSH =~ /password/i) { my $mire = print "$password\n"; } else { say "Connexion SSH $ip echec"; push @fail, $ip; say '-' x 20; next } if ($SSH =~ /[>]$/) { foreach (@CLI) { say "$_"; my $resultat = print "$_\n"; print "$resultat"; } } else { say "Commande show version KO"; push @fail, $ip; next; } } say; say '### Connexion SSH KO ###'; foreach (@fail) { say "$_"; } #### use strict; use warnings; use Data::Dumper; use feature 'say'; no warnings 'uninitialized'; use IPC::Open3; print 'Login: '; chomp (my $login = <>); print 'Password: '; chomp (my $password = <>); print 'Fichier IP: '; chomp (my $SOURCE = <>); print 'Fichier ligne de commandes:'; chomp (my $commande = <>); my $cmd = 'ssh -o StrictHostKeyChecking=no -o ConnectTimeout=3 -l'; my $pid = open3(\*WRITER, \*READER, \*ERROR, $cmd); #if \*ERROR is 0, stderr goes to stdout while( my $output = ) { print "output->$output"; if ($output =~ /username/i) { print WRITER "nsoc-iec\n"; } }