Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I am new too. I have some experience using scripts but am no where near proficient. I have used the ssh shutdown script and it works great one machine ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2012
    Posts
    13

    Lan shutdown script problem for RHEL5u5


    Hi,
    I am new too. I have some experience using scripts but am no where near proficient. I have used the ssh shutdown script and it works great one machine at a time but like Hudak998 I have more than one machine. I actually can have as many as 200 machines online at any given time. I have a sript I have been trying to get to work and maybe someone here could help me figure out why it does not work. As you can read (below) 2 integers are required which is a range of machines. However it returns "machine_name is down". In reality the machines are up and I can ping them.
    HTML Code:
    #!/bin/bash
    #Author :Romaddave
    #Date : 5-3-2012
    #Purpose : Shutdown LAN PCs
    
    ERROR=165
    
    #Check if 2 parameters exist
    if [ $# != 2 ]
    then
    	echo This script requires 2  integer parameters
    	exit $ERROR
    fi
    
    MIN=$1
    MAX=$2
    while [ $MIN -le $MAX ]
    do
    	ssh -o NoHostAuthenticationForLocalhost=yes root@192.168.9.$MIN shutdown -h now > /dev/null
    	STATUS=`echo $?`
    	if [ $STATUS = 0 ]
    	then
    			echo view$MIN is Shuting down
    	else
    			echo view$MIN is not Responding
    	fi
    	let "MIN +=1"
    done
    
    #END

  2. #2
    Just Joined!
    Join Date
    Mar 2012
    Posts
    13
    Thanks to whomever put this in HTML for me. Hope I haven't broken any rules. This is the first forum I have ever been a part of and I look forward to sharing if I can.

  3. #3
    Just Joined!
    Join Date
    Mar 2012
    Posts
    13

    LAN shutdown

    OK, using a new script and network wide shutdown now works. Only problem is I am asked for the root password for each host machine selected for shutdown. So that is 145 times I have to put in the password. Not time efficient. Quicker if I just go around and power down all the machines manually.

    The rsa keys match so I can't figure out why it's asking for a password (please read the script before replying to this). In the script I am using:

    "ssh -o NoHostAuthenticationForLocalhost=yes root@view$MIN shutdown –h now > /dev/null" This should bypass the requirement for a password - right?

    I am using a new script that I inherited from the previous admin who was better than me at shell scripts. What I posted before was my attempt - and it failed. I found this one buried in archived files. I have attached the text file here for someone - anyone - to look at. Please someone respond. Because both scripts look the same to me. LAN-Shutdown.txt
    Last edited by romaddave; 03-17-2012 at 04:52 PM. Reason: missing information in post.

  4. #4
    Linux Guru Lazydog's Avatar
    Join Date
    Jun 2004
    Location
    The Keystone State
    Posts
    2,677
    Have you thought about using ssh-keys for this?
    What you would do is generate a key for root and then copy the public key to all the servers.
    Then you could shutdown the servers with:
    Code:
    ssh <ip> shutdown -h now
    and the server would be shutdown without the need for the password as the key would be the authenticating method.

    Just adjust your script accordingly.

    Regards
    Robert

    Linux
    The adventure of a life time.

    Linux User #296285
    Get Counted

  5. #5
    Just Joined!
    Join Date
    Mar 2012
    Posts
    13
    Thanks Lazydog, all my other machines are client machines and they mount the home directory of the server. I only have the one server in my network and want to shutdown all the other clients from there. BTW I am using RHEL 5.5

    I did generate the keys in /root/.ssh as id_rsa.pub and copied it to the folder /etc/ssh of each client machine as ssh_host_rsa_key.pub. I also have two other files there called ssh_host_dsa_key.puband ssh_host_key.pub that I did not create. I do not have any output of the key creation process to show but it was successful according to the screen readout. From everything I have read there is supposed to be a file called authorized_keys but it does not exist anywhere on my client machines. Don't know if this is why I still have to enter the password on each machine.

    So I am still at a loss as to why I have to put in the password each time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •