Link to home
Start Free TrialLog in
Avatar of yogio
yogio

asked on

Linux For Loop

How can I write a script to shutdown some remote Linux servers.  I believe I need to create a list of IP addresses for the servers to have the script loop to it, then ssh into as root and shut it down with the shutdown command.  Thanks
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
With ssh, after issuing the shutdown, you have to also issue an exit, or the shutdown, might lock your session.
Usually root login might not be allowed, the use of a Setuid script or sudo shutdown now ;exit might be a way to go.
There shouldn't be a hang - the ssh call will run the command and exit as soon as it finishes.

It can be a problem if you log onto the remote server and issue the "shutdown now" command manually.  In that case, you could issue the command
    exec shutdown now
so that the session ends as soon as the command completes (and before the machine shuts down).
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yogio
yogio

ASKER

Thanks for all the help.