The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Basic Java Persistence API Best Practices iBot Oracle Updates (RSS) 0 06-06-2008 07:10 PM
Korn Shell Best Practices mtravis Shell Programming and Scripting 1 02-14-2008 03:11 PM
Emergency boot dags SCO 2 04-14-2005 10:00 AM
Scripting Best Practices toddjameslane UNIX for Dummies Questions & Answers 5 03-26-2005 02:09 PM
User generated FAQ and Best Practices section kduffin Post Here to Contact Site Administrators and Moderators 5 11-21-2003 09:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-08-2008
jsw371 jsw371 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 8
emergency shutdown best practices.

Has anyone implemented or have suggestions on how to shutdown many remote unix/linux servers from a single script initiated from 1 server?

I need this to execute in parallel as time is not on my side. Our ups is sadly underrated and will die in approximately 15 minutes. (There is not any money in the budget to upgrade the ups.)
  #2 (permalink)  
Old 10-08-2008
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
If you can ssh around as root
Code:
for host in `cat hostlist`; do ssh $host shutdown <arguments>;done
(assuming that you put all of the hosts in a file named hostlist)
  #3 (permalink)  
Old 10-08-2008
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
If you have more than 15 minutes to plan for "emergency shut down" of your servers, I'd recommend:

1. All applications that are running have corresponding startup and shutdown scripts in rc.*
2. Identify the order that your hosts should be shutdown in - NIS or LDAP should shutdown last, NFS servers second last... NTP would go first...
3. Write scripts.
You need to send a wall to all users connected informing them of an impending outage.
You need to ensure that you send the right shutdown options to the right OS types.
You need to create for each command that you are sending - for audit and CYA purposes later.
4. Inform your business/clients/users that these are the "emergency shutdown" procedures. Get them to sign-off and buy into them. If they have special requirements, amend your policy to include those.

Ensure that you have adequate time to shutdown storage devices that may have a great deal of data in cache. Ensure that you have adequate time to shutdown tape storage systems, as the robotics may need more time to get to "home" than you might expect.

There is no shortage of things that you could do, but this should get you started.

Last edited by avronius; 10-08-2008 at 02:17 PM.. Reason: Grammer
  #4 (permalink)  
Old 10-08-2008
jsw371 jsw371 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 8
Here in lies the problem. Our network security officer will not allow ssh as root. Also, we have many "flavors" of unix/linux which have different shutdown options. I tried something like this but it does not work on all the servers. (They do not like the <<\EOT...EOT construct)
$1 is list of remote servers. mbaker has sudo root privilege

cat $1 | while read X
do
echo "Starting shutdown of $X"
ssh -T ${X} << \EOT >> Emergency_shutdown.log 2>> error.log
name=`uname -n`
echo "name = $name"
type=`uname -a | awk '{print $1}'`
echo "type = $type"
if [ "$type" = "SunOS" ]
then
echo "Emergency shutdown initiated for $name."
# sudo -u root shutdown -y -i5 -g0 "Emergency shutdown started!!!!!" &
fi
if [ "$type" = "Linux" ]
then
echo "Emergency shutdown initiated for $name."
sudo -u root /sbin/shutdown -k now "This is just a test. Not really re-booting." < /dev/null > /dev/null 2>&1 &
fi
EOT
if [ $? -ne 0 ]
then
echo "Host $X connect failed."
fi
done
exit 0
  #5 (permalink)  
Old 10-08-2008
broli's Avatar
broli broli is offline
Registered User
  
 

Join Date: Dec 2007
Location: Argentina
Posts: 212
the best way is to create an script per server. called something like
"emergency-shutdown.sh"
and call that one.
and put all the os specific commands on each server
its harder to maintin maybe, but is cleaner, and more flexible.
  #6 (permalink)  
Old 10-08-2008
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
can you do this as user mbaker:


Code:
for host in `cat hostlist`; do ssh $host sudo -u root ifconfig -a;done
without being asked for a password? (In Solaris, only root can see MAC address - it's a harmless test).

Depending on how your systems are config'd, you may be able to sudo without providing a password. If you DO need a password to do the sudo, you could add some scripting magic to wait and apply the password, but it's not terribly secure...
  #7 (permalink)  
Old 10-08-2008
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
Good point Broli - since you are already using sudo, create the shutdown scripts (one script for all hosts - perform the OS check locally), and give mbaker the right to run the shutdown script.
Then, your script would simply be:
Code:
for host in `cat $hostlist` do; ssh $host emergencyShutdown <flags/options>;done
Sponsored Links
Closed Thread

Bookmarks

Tags
unix commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 02:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0