LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-01-2010, 06:22 AM   #1
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Rep: Reputation: 31
Shutdown multiple computers via ssh, try different passwords


I'm trying to write a mass reboot script in the event of a power outage (servers go to UPS for some 15 minutes or so and shutdown uncleanly).

What I have is a set of 6 common passwords which will be prompted for per ssh connection, is there any way I can cycle through this password list

Code:
#below is an example of how this is constructed, IP's are used instead of hostnames due to the possibility of a DNS server being offline. 
SERVERSRM1="1 2 3"
SERVERSRM2="110 120 130"

for i in $SERVERSRM1; do ssh -n root@192.168.0.$i "hostname && shutdown -y -i5 -g0"; done;'
for i in $SERVERSRM2; do ssh -n root@192.168.0.$i "hostname && shutdown -y -i5 -g0"; done;'
Each time the code is executed I'm prompted for a password (it's always one of 6 passwords). It would be quicker to have the passwords be cycled through.

Can anyone help. I realise this is basic code at the moment but it will eventually allow for a specific set of computers to be shut down based on what power supply they're using.

authorized keys not really an option given the scale of computers (some 300 or so).

Last edited by genderbender; 10-01-2010 at 06:24 AM.
 
Old 10-01-2010, 08:32 AM   #2
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
Right, seems like I need to use except which I've got working quite well...

I just have one problem now concerning expect, some of my ssh logins have a motd banner, is there anyway I can make expect ignore these banners and continue typing text? You'll have to forgive how crap I am with except, it's a new tool for me so I'm not great with it (I don't intend to use it again due to difficulties I've had running it).
 
Old 10-01-2010, 08:52 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
Just out of curiosity what type of UPS are you using and are they connected via serial or USB to the servers? The two UPS tools that I am familiar with i.e. apcupsd and NUT have a network capability so one computer can shutdown all the rest without having to manually send commands.
 
Old 10-01-2010, 08:59 AM   #4
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by michaelk View Post
Just out of curiosity what type of UPS are you using and are they connected via serial or USB to the servers? The two UPS tools that I am familiar with i.e. apcupsd and NUT have a network capability so one computer can shutdown all the rest without having to manually send commands.
APC smartups, servers are connected by iec cables, however there's snmp on the smartups's, so the second they switch on I've got some time to shut everything down with my rather crap script, lol. This is uninterruptable power supply, i.e in the event of power loss switch to battery power, server's aren't informed of the power loss as such, they just continue working unaware.
 
Old 10-01-2010, 09:37 AM   #5
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
You should be able to set up the server so that it is aware that the UPS is on. The last time I did this the APC UPS came with a serial cable for this very task.
 
Old 10-01-2010, 09:40 AM   #6
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
300 serial cables... I'll give it a miss, haha. OK so am I to conclude that this isn't going to be possible or easy?
 
Old 10-01-2010, 09:45 AM   #7
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Well you could look at network shutdown
 
Old 10-01-2010, 09:51 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
BTW it is possible to use the same public/private key on all of the servers.
I assume that there is a RS-232 or USB port in addition to ethernet so you could run apcupsd on one server to control all of the others via the network.

I have not played with expect much so can't help you there.

Last edited by michaelk; 10-01-2010 at 09:52 AM.
 
Old 10-01-2010, 10:09 AM   #9
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
This is what I ended up doing:

Wrote an except script which takes three variables, username, password and server.
Made a bash script which cycles through all the addresses in the whole building.
Any time it failed to login I wrote down the IP's and assumed they were using a different password and created a seperate function for the next set of IP's.
Continued doing this until i had 6 functions with different passwords in.
Made a script which runs each of the functions.

Still can't get past the banners though, if theres' a banner I cant execute any commands and have to wait until the connection times out
 
Old 10-01-2010, 02:46 PM   #10
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
on each server create a new user without shell, and add it to the sudoer file like:
shutdowner ALL=(ALL) NOPASSWD: /sbin/shutdown
then the script to shutdown all your server at once is:
Code:
for IP in $SERVER_IP; do
   sshpass -p $PASSWD ssh -t shutdowner@$IP "sudo /sbin/shutdown -h now"
done
But i'm sure it rise many security issues...
 
Old 10-01-2010, 02:59 PM   #11
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
I'd suggest checking out somethign like func. no ssh, no passwords, no login shells, just commands like "func server*.domain.com call command run shutdown" to blanket shut down all servers matching a hostname pattern. doddle.

https://fedorahosted.org/func/
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ANNOYING FREEZES: Happens on multiple distributions on multiple computers. keithieopia Linux - Software 26 02-23-2009 02:36 PM
SSH to multiple computers behind firewall hazmatt20 Linux - Networking 13 08-17-2006 01:32 PM
linking computers via internet to brute force passwords scott1981 Linux - Security 10 03-16-2006 07:05 PM
Multiple Passwords Stephanie Linux - General 2 08-31-2002 12:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration