problems writing script to turn off remote computers using ssh
Hello,
I have been trying to write a script in linux(Red Hat) to turn off remote computers using ssh. The problem I am facing right now is to determine which computers are already powered off. I was thinking of using the fping utility but realised that it's not available by default, so now I am lefr with the option of PING and i have no idea how to do that in a script, I mean how to parse the output of ping and use it to my benefit. Thanks in advance for your help. |
Hi,
you can use like below, instead of echo use whatever you want. ping -c 1 -W 2 $1 > /dev/null value=`echo $?` if [ "$value" -eq 0 ] ; then echo "Server is up" else echo "server is down" fi execute the script with the input of server ip address or hostname. |
something like that sounds a bit like it might be used for
shall we say -- not so good of a purpose ... ping might not not work iptables normally is set to be invisible a ping might not be returned even if the machine is on |
probably you can try nmap and look for ssh port.
|
NMAP would be more accurate if used:
Code:
nmap -p22 IP_address_of_host (or hostname/domain) |
Quote:
|
well RHEL is set up to have all ports hidden
that is the default setting in iptables nmap should then NOT receive a replay one way or the other all ports should look like there is no computer there. |
Why not just tell them to shut down via ssh regardless? If the machine is already down, it won't be available to connect. You can use the ConnectTimeout option in ssh so it doesn't wait forever for it to respond. If you set the timeout to just a few seconds, it shouldn't take much longer than trying to ping a dead computer anyway.
|
All times are GMT -5. The time now is 02:39 PM. |