LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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-16-2011, 11:41 PM   #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, 12:08 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 09: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, 09:14 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,317
Blog Entries: 28

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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:39 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