1833983 Members
1948 Online
110063 Solutions
New Discussion

script writing

 
SOLVED
Go to solution
NPD USER
Regular Advisor

script writing

Hello,

I would like to create a script that will shutdown multiple servers at once. I would also like the script to execute the shutdown command on 1 server and then move to the next without waiting for the 1st server to be completly down. Does anyone know how I would do this. This is the command I'm executing within the script:

remsh $SERVER "shutdown -h -y 0" > /dev/null 2&>1 < /dev/null

However, this command still waits on the 1st server before going to the next.

Thanks,
Scott
4 REPLIES 4
Vitek Pepas
Valued Contributor
Solution

Re: script writing

You have to add '&' sign at the end of the command to run it in background, and perhaps start it with 'nohup'.
James Murtagh
Honored Contributor

Re: script writing

Hi Scott,

You could use :

remsh $SERVER "/sbin/shutdown -h y 0 &"

I don't think you'll get any output directed to your stdout this way so you shouldn't have to redirect it after this.

cheers,

James.
GK_5
Regular Advisor

Re: script writing

Use & at the end of the command. It will run the command in background and will return the prompt for next command.
IT is great!
Steven E. Protter
Exalted Contributor

Re: script writing

Assumes secure shell/openssh

ssh hostname1 "shutdown -ry now" &
ssh hostname2 "shutdown -ry now" &
ssh hostname3 "shutdown -ry now" &

Check the server in question.

If roots home directory is /home/root then you will need to change the command.

ssh hostname1 "cd /; shutdown -ry now" &
ssh hostname2 "cd /; shutdown -ry now" &
ssh hostname3 "cd /; shutdown -ry now" &

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com