user786 has asked for the wisdom of the Perl Monks concerning the following question:

Net::ssh::expect allows us to login to a remote router and run commands.

Is there way to run these commands in a single line. I mean is there a way to execute the three commands listed below with one single variable $cmd instead of using $cmd1, $cmd2, $cmd3 for ls, configure and exit respectively.

my $cmd1 = $ssh->exec("ls"); my $cmd2 = $ssh->exec("configure"); my $cmd3 = $ssh->exec("exit");
For remote login we do the following:
my $ssh = Net::SSH::Expect->new (host => "ip addr", password=> 'pwd', user => 'username', raw_pty => 1);

similarly is there a way to execute commands?

Replies are listed 'Best First'.
Re: cpan module to execute multiple commands
by jeffa (Bishop) on Jun 18, 2014 at 21:18 UTC

    There are many different ways to achieve what you desire, some better than others. Have you tried this simple trick?

    my $return = $ssh->exec( 'ls; configure; exit' );

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)