in reply to Net::OpenSSH multiple commands

I don't know who this might help, but here is a simple way to join multiple commands and run them at once on a remote server. It just connects to the server, finds the directory you want, and prints its total contents. --Ben.
#!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; my $ssh = Net::OpenSSH->new(host=>"$host, user=>"$user, port=>$port, p +assword=>$password); my $cmd1 = 'cd /path/to/file'; my $cmd2 = "ls -a\n"; my $cmd3 = join ('&&', $cmd1, $cmd2); print $cmd3; $ssh->system($cmd3);

Replies are listed 'Best First'.
Re^2: Net::OpenSSH multiple commands
by salva (Canon) on Apr 07, 2013 at 20:06 UTC
    It is recommendable to let Net::OpenSSH quote the command arguments. Double references can be used to let some fragment pass unquoted:
    my @cmd1 = (cd => $path_to_file); my @cmd2 = (ls => '-a'); $ssh->system(@cmd1, \\'&&', @cmd2)
    Otherwise, in case $path_to_file contained shell metacharacters it could produce undesired results or even be a security hole.

    Note that currently, argument quoting expect some derivative of the Bourne shell on the remote side. Support for quoting arguments for other shells is in the works though.