943,383 Members | Top Members by Rank

Ad:
May 19th, 2004
0

shuting down multiple nix boxes

Expand Post »
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?

cheers,

spikes
Similar Threads
Reputation Points: 11
Solved Threads: 2
Junior Poster
spikes is offline Offline
106 posts
since Jul 2003
May 19th, 2004
0

Re: shuting down multiple nix boxes

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"

Notes:

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.

Christian
Team Colleague
Reputation Points: 121
Solved Threads: 57
Posting Virtuoso
kc0arf is offline Offline
1,629 posts
since Mar 2004
May 19th, 2004
0

Re: shuting down multiple nix boxes

Quote originally posted by kc0arf ...
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)
DMR
Team Colleague
Reputation Points: 221
Solved Threads: 369
Wombat At Large
DMR is offline Offline
6,439 posts
since Dec 2003
May 19th, 2004
0

Re: shuting down multiple nix boxes

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.
Last edited by alc6379; May 19th, 2004 at 9:03 pm.
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003
May 19th, 2004
0

Re: shuting down multiple nix boxes

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:


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

DESCRIPTION
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.
Reputation Points: 128
Solved Threads: 8
Posting Whiz
TheOgre is offline Offline
390 posts
since Aug 2003
May 20th, 2004
0

Re: shuting down multiple nix boxes

Hey,
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.

spikes
Reputation Points: 11
Solved Threads: 2
Junior Poster
spikes is offline Offline
106 posts
since Jul 2003
May 21st, 2004
0

Re: shuting down multiple nix boxes

Hello,

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.

Christian
Team Colleague
Reputation Points: 121
Solved Threads: 57
Posting Virtuoso
kc0arf is offline Offline
1,629 posts
since Mar 2004
May 22nd, 2004
0

Re: shuting down multiple nix boxes

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sploo22 is offline Offline
1 posts
since May 2004
May 24th, 2004
0

Re: shuting down multiple nix boxes

thanks for that,
i'll give it a try.

spikes
Reputation Points: 11
Solved Threads: 2
Junior Poster
spikes is offline Offline
106 posts
since Jul 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Linux Applications and Software Forum Timeline: FreeBSD only assigning inet6 addresses to ndis0
Next Thread in Linux Applications and Software Forum Timeline: Programming in Linux?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC