The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Running script on remote machine vickylife UNIX for Advanced & Expert Users 3 11-17-2008 05:45 PM
To invoke a script on a remote machine sam_roy SUN Solaris 5 10-08-2008 12:31 PM
Checking the status of the script on remote machine nua7 Shell Programming and Scripting 3 07-24-2008 02:41 AM
how to execute a script on remote machine balireddy_77 Shell Programming and Scripting 4 09-27-2006 07:45 PM
leave a process running in a remote machine pbasil UNIX for Dummies Questions & Answers 3 03-15-2006 10:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-20-2008
hcclnoodles hcclnoodles is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 272
running script in background on remote machine

Hi there

I have a script which is running a remote command on hundreds of boxes, it takes around 5 minutes to return an output from this command and because i am running this all from a central box, it goes off to each box in my for loop sequentially meaning that my script will wait for output before moving to the next machine

so as an example i will use the command `sleep 30`. I tried putting an ambersand into the script to no avail...the output on my central server still sits and waits for each box to sleep for 30 seconds rather than sending the command off to a box, letting that box deal with it and moving onto the next box with no delay

an example

Code:
for hostname in $list
do
/usr/ucb/echo -n  "$hostname - "
ssh $hostname 'sleep 30 &'
done

output ....ZZZZzzzzz


Code:
myserver1 -                       (waits 30 seconds then..)
myserver2 - 
..
..
..

Is there a way to do this ??
  #2 (permalink)  
Old 11-20-2008
Konerak Konerak is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 20
First of all, you'll want the "ssh" command to return. So you add the ampersand to the ssh command, not (only) the sleep command.

Second problem: as the ssh returns, the remote server might terminate the process. Use "nohup" to fix that.

ssh $hostname 'nohup sleep 30 &' &

How's that do?
  #3 (permalink)  
Old 11-20-2008
hcclnoodles hcclnoodles is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 272
ill give it a go, be right back
  #4 (permalink)  
Old 11-21-2008
hcclnoodles hcclnoodles is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 272
mmm, didnt work,

I added the & to the nohup command first and the central script still waited 30 secnonds before moving on to the next box.

Adding the additional & to the overall ssh command, did the same thing but just put it all in the background on the central server, so i didnt get any output ....still took just as long

any other ideas?
  #5 (permalink)  
Old 11-21-2008
minkie minkie is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 3
try this:

ssh $hostname 'nohup sleep 30 > /dev/null 2>&1 &'


SSH Frequently Asked Questions
  #6 (permalink)  
Old 11-21-2008
hcclnoodles hcclnoodles is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 272
cheers Minkie youre a legend
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0