LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-11-2008, 08:41 AM   #1
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Rep: Reputation: 33
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

Last edited by knockout_artist; 11-11-2008 at 08:56 AM. Reason: change in title
 
Old 11-11-2008, 09:59 AM   #2
lukav
Member
 
Registered: Sep 2008
Distribution: Slackware & Ubuntu
Posts: 39

Rep: Reputation: 15
Try using single quotes around your remote command

For example:

Code:
./program.pl 10.10.10.10 'pwd && ls'
 
Old 11-11-2008, 10:04 AM   #3
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Original Poster
Rep: Reputation: 33
Nope!

Same results.
 
Old 11-11-2008, 10:39 AM   #4
rizwanrafique
Member
 
Registered: Jul 2006
Distribution: Debian, Ubuntu, openSUSE, CentOS
Posts: 147

Rep: Reputation: 19
change
Code:
system("ssh root\@$ipary  $ARGV[1]");    ## execute ssh command
to
Code:
system("ssh root\@$ipary  \"$ARGV[1]\"");    ## execute ssh command
 
Old 11-11-2008, 10:57 AM   #5
knockout_artist
Member
 
Registered: Sep 2005
Distribution: fedora core 9
Posts: 324

Original Poster
Rep: Reputation: 33
system("ssh root\@$ipary \'$ARGV[1]\'"); ## execute ssh command

That worked!

Thanks Rizwan.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute a Perl script in ~/.procmailrc with SELinux set to Enforcing? thomasz Linux - Security 1 03-14-2008 05:25 AM
Perl:Not able to execute command in variable jags.singh Programming 1 07-23-2007 07:51 AM
perl script to execute my a c executable on remote machin sharad Linux - General 5 12-14-2006 07:56 AM
Getting PID from a system command in Linux perl script sumbabs Linux - General 1 03-03-2005 10:38 AM
Why cant i execute a perl script dude4you Linux - Newbie 2 03-02-2004 05:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration