Hi all Working with a linux virtual machine without the possibility to install any module, my goal is to connect in SSH to several material and without the result in STDOUT, pass in console some command. I tried without success

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 "$_"; }

RESULT:

ZZZ@YYY:~$ perl SSH.pl

Login: TOTO

Password: TATA

Fichier IP: SSH.txt

Fichier ligne de commandes:SSH-commandes.txt

User Access Verification

Username:

I made another trie simpler with the module IPC::Open3 in the core to read and write the process but no more success.

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 = <READER> ) { print "output->$output"; if ($output =~ /username/i) { print WRITER "nsoc-iec\n"; } }

RESULT:

ZZZ@YYY:~$ perl SSH.pl

Login: TOTO

Password: TATA

Fichier IP: SSH.txt

Fichier ligne de commandes:SSH-commandes.txt

ZZZ@YYY ~/SCRIPT

$

Someone have a lead ?

Thanks


In reply to SSH and expect without module by touriste75

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.