Shutdown all systems remotely

Hi,
I am a sysadmin. During long weekends i need to turn off all machines in my lab. Is it possible to shutdown systems using ip address without using ssh.

i read somewhere that shutdown -m "IPADDR" may work. However it seems its a windows specific command.

So my question is how do i remotely shutdown all machine in my LAN using their IP address.

just write a script that does the shutdown for you...

How do i write that script? Writing a script that ssh to each system will be very tedious as i ll have to first create public key pair for around 100 systems. Is there a easier/simpler way to do this?

Yes. Create 1 key-pair & copy it to all 100 systems. You don't necessarily need a different one for every system.

or use "expect" to spawn a ssh session and send the password to the servers...

Their solutions were "push" solutions. You could do a "pull" solution: Write a cronjob to run every minute (or 15 minutes, or whatever); it uses curl to check a web page on your server; if the file exists, the cron job initiates a local shutdown.

  if curl -s -i -I http://my.server.ip:port/power-off-`date +%F` | head -1 | grep " 200 OK" >/dev/null ; then 
        shutdown -h now
  fi

On the server, simply run a web server and point the document root somewhere you can write to, and when you want the systems to shut down, simply cd into the web server's document root directory and do:

   touch power-off-`date +%F`

The date makes sure the systems dont power off at startup the following day.

If you want to make it secure, generate a self-signed SSL key and distribute the cert to all the hosts.

I manage 248 servers and use pludi's method. Makes pushing out updates much easier too :smiley:

Use public keys and sudo. But even then, I think only root can perfom a shutdown.

Good luck!

At my job we have the ability to ssh into over 80 servers and shut them down using "sudo /etc/shutdown -y -g0".

Crude but quick:

With the key/pair solution implemented, you could issue a for loop.

Script:

#!/bin/sh
for x in `cat ./server_list`
do
    ssh $x "/sbin/shutdown <time>"
done

Example content of file 'server_list':

server1
server2
server3

If your systems support IMPI, you might want to take a look at that.

Intelligent Platform Management Interface - Wikipedia, the free encyclopedia

If it has a LOM capability, it'll make this a lot easier. More modern servers have this.

you should look into using tools like capistrano and puppet to do these tasks. you don't even need keys with capistrano, though it does make things easier.

there are similar tools out there, like func, and mcollective.

some links:

Capistrano
Puppet Labs: The Leading Open Source Datacenter Automation
mcollective - Project Hosting on Google Code