LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   perl script system() only execute one command (http://www.linuxquestions.org/questions/programming-9/perl-script-system-only-execute-one-command-682617/)

knockout_artist 11-11-2008 08:41 AM

perl script system() only execute one command over ssh
 
Code:

#!/usr/bin/perl

$acc = "root";
$ips=$ARGV[0];                    ## this holds the command needs to run on remote host.
@ipary= split(/\,/,$ips);      ## split if there are more then one host
for $ipary(@ipary){

print ("\n");
print "connecting ......$ipary \n";


system("ssh root\@$ipary  $ARGV[1]");    ## execute ssh command

}

Problem here is if I do
Code:

./program.pl  10.10.10.10  "pwd  && ls "
It execute pwd on remote host BUT it execute ls on local host.
I have done same with shell script in a different environment(some where else) and it worked

AND
Now
I have used normal shell
as
Code:

ssh root@10.10.10.10  "pwd &&  ls"
Above command execute both command on remote host.


Thanks

lukav 11-11-2008 09:59 AM

Try using single quotes around your remote command

For example:

Code:

./program.pl 10.10.10.10 'pwd && ls'

knockout_artist 11-11-2008 10:04 AM

Nope!

Same results.

rizwanrafique 11-11-2008 10:39 AM

change
Code:

system("ssh root\@$ipary  $ARGV[1]");    ## execute ssh command
to
Code:

system("ssh root\@$ipary  \"$ARGV[1]\"");    ## execute ssh command

knockout_artist 11-11-2008 10:57 AM

system("ssh root\@$ipary \'$ARGV[1]\'"); ## execute ssh command

That worked!

Thanks Rizwan.


All times are GMT -5. The time now is 03:03 AM.