Hi All,
anyone have a bright idea for me. i have one linux box attached to an UPS system. when the battery is low it tells the linux box to shutdown.

is there a way that i can get this box to signal other linux boxes to shutdown as well?



13 Years
Discussion Span
Last Post by spikes

Hello Spikes,

Yes there is. You will need to use the root account on those computers, and it could be a security issue if you don't properly protect the script file, but there is a way.

On the computer with the UPS connection, you will need to write a script that will contact the other computers, and down them for you.

I would use the EXPECT script language which will allow you to use telnet/ssh (I prefer ssh), and from there, in psuedo code:

send "ssh -l root box1name\r"
expect "password"
send "the root password\r"
expect "prompt#"
send "shutdown -h now\r"
expect "prompt#"
send "exit\r"
expect "prompt"


1) Expect might not be installed. Go install it.
2) If you do not lock the file properly (root read permissions only!), it is a security leak with the root password in there
3) shutdown -h now will bring the box down right then and there. Do a man shutdown and see if you can give the users a few minutes to logoff properly
4) The \r in the script is a return character. Need it for syntax reasons. Do a man expect to get the rest of the syntax. I would copy some code for you if I had a shell access to my box.
5) Test it when you are standing in front of the system to make sure the commands propogate properly
6) Make sure your network hubs are on the UPS. If the hub is already out of power, no telnet / ssh will work to reach the other boxes.
7) If you change the root password, you will need to update your scripts. Same if you change IP numbers / DNS names.

Good Luck.



3) shutdown -h now will bring the box down right then and there. Do a man shutdown and see if you can give the users a few minutes to logoff properly

The "-t" option controls that (in seconds). For example:

/sbin/shutdown -t 60 -h

To wait 1 minute before halting the system(s)


I thought the standard action of shutdown was to wait a minute? Hence the necessity for,

shutdown -h now

under Linux/FreeBSD, or

shutdown -yg0

on some other UNIX systems.


shutdown -h now is essentially "shutdown HARD, now!" (both under Slackware and FreeBSD) with no delay whatsoever.

shutdown -r now means "Reboot, now!" (also in Slack/FBSD)

If you want to specify a time delay, follow DMR's example.

Here's the manpage from a FreeBSD system:

shutdown [-] [-h | -p | -r | -k] [-o [-n]] time [warning-message ...]

Shutdown provides an automated shutdown procedure for super-users to
nicely notify users when the system is shutting down, saving them from
system administrators, hackers, and gurus, who would otherwise not bother
with such niceties.

The following options are available:

-h The system is halted at the specified time.

-p The system is halted and the power is turned off (hardware sup-
port required) at the specified time.

-r The system is rebooted at the specified time.

-k Kick everybody off. The -k option does not actually halt the
system, but leaves the system multi-user with logins disabled
(for all but super-user).

-o If one of the -h, -p or -r is specified, shutdown will execute
halt(8) or reboot(8) instead of sending signal to init(8).

-n If the -o is specified, prevent the file system cache from being
flushed by passing -n option to halt(8) or reboot(8). This
option should probably not be used.

time Time is the time at which shutdown will bring the system down and
may be the word now (indicating an immediate shutdown) or specify
a future time in one of two formats: +number, or yymmddhhmm,
where the year, month, and day may be defaulted to the current
system values. The first form brings the system down in number
minutes and the second at the absolute time specified.


Thanks for all the advice, but we seam to have skiped one point.

when the ups sends a shutdown command to the box, how can i then tell the box to run the remote shutdown script that we have been talking about.

the rest of the stuff is real helpful.




When you installed the UPS onto the linux box, there may have been some scripts that went along with it. You might also have to look into the scripts that your power manager works with (APD)? You did not specify what version of linux you have.

From there, if they are scripts, you will need to insert code to trigger off the transmissions to your other boxen.



A much more secure and efficient way to do this is to use SSH public keys.

First, on the "master" computer (the one with the UPS) run the program "ssh-keygen -t dsa". Give the key a blank passphrase, and save it in the default location. Now you should have in your ~/.ssh/ directory two files: id_dsa and id_dsa.pub.

Copy the id_dsa.pub file to the other computers, put it in a directory called .ssh in root's home directory (/root) and rename it to authorized_keys. Hopefully, this will now let you ssh to the other computers without a password. This way, you don't need to use expect and can shut down a computer with the command

ssh computername "shutdown -h now"

This system is completely secure, as long as you keep the private key (id_dsa) safe. It also avoids having the password stored unencrypted in the script, which is extremely dangerous.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.