Unix/Linux Go Back    


Fedora is an operating system centered on the Linux open source kernel and is developed by the community-supported Fedora Project. Fedora is sponsored by Red Hat. Fedora contains software distributed under a free and open-source license. Fedora focuses on innovation, integrating and adopting new technologies and working closely with various Linux communities. The default desktop in Fedora is the GNOME desktop environment and the default user interface is the GNOME Shell. Other desktop environments include KDE Plasma, Xfce, LXDE, MATE and Cinnamon. Security is an important aspect of Fedora with one specific security feature, Security-Enhanced Linux, implementing a variety of software security policies, including mandatory access controls.

Script for shutting down 48 computers

Fedora


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-16-2015
Jeff Rollins Jeff Rollins is offline
Registered User
 
Join Date: Apr 2015
Last Activity: 16 April 2015, 8:05 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Script for shutting down 48 computers

Hi All, I am pretty new to unix type languages. At work we have a server room with about 50 windows computers in one system and 50 in a unix system. We sometimes have power outages and I don't like the power slam. I wrote a windows batch file using sysinternals help to shutdown the windows computers. I am trying to write one for the unix servers. I started by using vi editor. I remember a little from school. Anyhoo, I start from one of the computers (I use ACC36 because that is where my KVM is. all are names ACC###)ACC36 and
Code:
ssh ACC30

to get to ACC30. Then my next line is
Code:
init 0

this is the shutdown command.
My next command is to get back to ACC36 before the shutdown is
Code:
ssh ACC36

Well, that works, but when I repeat the commands in the script for the other ACC's, it never goes past the first return to ACC36. After I write and save it with :wq , I then
Code:
chmod 755 power-off

Then to execute I go
Code:
./power-off

What am I doing wrong? Any help would be appreciated.
Sponsored Links
    #2  
Old Unix and Linux 04-16-2015
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 June 2017, 5:46 PM EDT
Location: Aachen, Germany
Posts: 10,947
Thanks: 277
Thanked 3,365 Times in 3,098 Posts
Try
Code:
while read COMP; do echo ssh $COMP init 0; done < complist

and supply the computer names in that list. I assumed e.g. ssh ACC36 will safely log you into that machine.
Remove the echo if you're happy with what you see.
Sponsored Links
    #3  
Old Unix and Linux 04-16-2015
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 22 June 2017, 12:41 PM EDT
Location: NM
Posts: 11,091
Thanks: 532
Thanked 1,067 Times in 989 Posts
If you shut down the computer the script is executing on - e.g., ACC36 is first in the list, you've lost scripting process. No more shutdowns. Be sure to run the script on the LAST ACCxxx box in your list of computers.
    #4  
Old Unix and Linux 04-16-2015
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 June 2017, 5:46 PM EDT
Location: Aachen, Germany
Posts: 10,947
Thanks: 277
Thanked 3,365 Times in 3,098 Posts
Depending on availability on your system, you might shutdown +5.
Sponsored Links
    #5  
Old Unix and Linux 04-16-2015
garydeena garydeena is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 12 August 2015, 10:47 PM EDT
Posts: 11
Thanks: 0
Thanked 2 Times in 2 Posts
I presume you are doing this as root. You allow root to ssh onto all your servers ?

Using rudiC example. Just add & on the end and/or </dev/null


Code:
while read COMP
 do 
     echo " Shutting down  "$COMP
     echo    ssh $COMP init 0  </dev/null  &  
 done < complist

If you are running remote ssh commands on a list of servers, you have to add
</dev/null at the end or it will exit after the first one.
With just </dev/null it will run the command on each server in foreground one after another.

You can also add & to the end and it will execute the command in background on each server and return at once.

Test the script with the echo first and then remove, when you want to use it.

Last edited by Scrutinizer; 04-17-2015 at 12:49 AM.. Reason: CODE tags
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Getting error while shutting down manoj.solaris AIX 1 09-27-2011 04:30 AM
Shell script to Shutdown Computers on Cluster marcozd Shell Programming and Scripting 1 12-08-2009 06:33 PM
Shutting down Solaris tonysequoia UNIX for Advanced & Expert Users 1 01-24-2006 02:47 PM
Script to get IP addresses of LAN computers sladuuch Shell Programming and Scripting 1 10-04-2005 03:10 PM



All times are GMT -4. The time now is 06:16 PM.