shuting down multiple nix boxes

Reply

Join Date: Jul 2003
Posts: 106
Reputation: spikes is an unknown quantity at this point 
Solved Threads: 0
spikes's Avatar
spikes spikes is offline Offline
Junior Poster

shuting down multiple nix boxes

 
0
  #1
May 19th, 2004
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
"it's not to old to do cool stuff, it's just to old to do it with graphics"
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: shuting down multiple nix boxes

 
0
  #2
May 19th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 6,439
Reputation: DMR will become famous soon enough DMR will become famous soon enough 
Solved Threads: 363
Team Colleague
DMR's Avatar
DMR DMR is offline Offline
Wombat At Large

Re: shuting down multiple nix boxes

 
0
  #3
May 19th, 2004
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)
"May the Wombat of Happiness snuffle through your underbrush."
- Ancient Aborigine blessing


Please do not contact me by email or PM for help. We're all volunteers here, and only have so much free time to dedicate to our efforts.

However, if I've been working on a thread with you already, and seem to have "forgotten" your thread, please do send me a message. I try not to let things slip through the cracks, but it does happen sometimes.
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: shuting down multiple nix boxes

 
0
  #4
May 19th, 2004
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.
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Join Date: Aug 2003
Posts: 372
Reputation: TheOgre is a jewel in the rough TheOgre is a jewel in the rough TheOgre is a jewel in the rough 
Solved Threads: 6
TheOgre's Avatar
TheOgre TheOgre is offline Offline
Posting Whiz

Re: shuting down multiple nix boxes

 
0
  #5
May 19th, 2004
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.
If you spend more on coffee than on IT security, you will be hacked.
What's more, you deserve to be hacked.
-- former White House cybersecurity czar Richard Clarke
Reply With Quote Quick reply to this message  
Join Date: Jul 2003
Posts: 106
Reputation: spikes is an unknown quantity at this point 
Solved Threads: 0
spikes's Avatar
spikes spikes is offline Offline
Junior Poster

Re: shuting down multiple nix boxes

 
0
  #6
May 20th, 2004
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
"it's not to old to do cool stuff, it's just to old to do it with graphics"
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: shuting down multiple nix boxes

 
0
  #7
May 21st, 2004
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
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 1
Reputation: sploo22 is an unknown quantity at this point 
Solved Threads: 0
sploo22 sploo22 is offline Offline
Newbie Poster

Re: shuting down multiple nix boxes

 
0
  #8
May 22nd, 2004
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.
Ah, the power of cheese!
Reply With Quote Quick reply to this message  
Join Date: Jul 2003
Posts: 106
Reputation: spikes is an unknown quantity at this point 
Solved Threads: 0
spikes's Avatar
spikes spikes is offline Offline
Junior Poster

Re: shuting down multiple nix boxes

 
0
  #9
May 24th, 2004
thanks for that,
i'll give it a try.

spikes
"it's not to old to do cool stuff, it's just to old to do it with graphics"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the *nix Software Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC