LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-17-2011, 12:41 AM   #1
aggrishabh
Member
 
Registered: Nov 2010
Posts: 87

Rep: Reputation: 1
executing shell script in background on remote machine


Hi All,

i need to execute a script in background on remote machines(say 10 machines) in parallel and in return i need the pid of that process. i tried few commands like below in for loop

ssh hostname "sh abc.sh &; echo $!"
with this command prompt is hung on host machine itself then i try

ssh hostname "sh abc.sh &; echo $!" &
but no luck ssh is going in back ground

any help will be highly appreciated.

NOTE: to some of u it look like homework but i search internet but not able to find proper answer.
 
Old 11-17-2011, 01:08 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Try with nohup
Code:
ssh hostname "nohup ./abc.sh &; echo $!"
CAUTION: Untested ...

PS I advise setting the shebang line at the top of the sh file & turn on execute perms, then you don't need to 'sh blah.sh'
 
Old 12-12-2011, 10:02 PM   #3
aggrishabh
Member
 
Registered: Nov 2010
Posts: 87

Original Poster
Rep: Reputation: 1
Sorry for replying late

i got chance to test this code (ssh hostname "nohup ./abc.sh &; echo $!")today only, it didn't work until the slight modification

ssh hostname "`nohup ./abc.sh &`; echo $!"

otherwise it will give below error
bash: -c: line 0: syntax error near unexpected token `;'


any other idea Please.
 
Old 12-12-2011, 10:14 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mint, OpenBSD
Posts: 11,340
Blog Entries: 12

Rep: Reputation: 2730Reputation: 2730Reputation: 2730Reputation: 2730Reputation: 2730Reputation: 2730Reputation: 2730Reputation: 2730Reputation: 2730Reputation: 2730Reputation: 2730
You might take a look at cluster ssh. I'm not sure it is simultaneous, but it's closest to what you are looking for that I have heard of so far.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 use ssh and run command in the remote machine using shell script salmanmanekia Linux - Newbie 8 04-28-2011 08:41 AM
[SOLVED] start up script seen in background but not executing allancuntapay Programming 19 11-18-2009 11:08 PM
verify if the same shell script is executing in background hicham007 Programming 2 08-07-2005 06:40 AM
telneting remote machine from a shell script sanjith11 Programming 11 05-26-2004 07:50 AM
Running a script in background on a remote machine TheCoffeeMug Linux - Networking 3 11-06-2003 11:08 AM


All times are GMT -5. The time now is 10:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration