Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
06-24-2012, 11:30 PM
|
#1
|
LQ Newbie
Registered: Jun 2012
Posts: 2
Rep:
|
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.
|
|
|
06-25-2012, 12:19 AM
|
#2
|
Member
Registered: Jan 2009
Location: Coimbatore, India
Distribution: rhel
Posts: 49
Rep:
|
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.
|
|
1 members found this post helpful.
|
06-25-2012, 02:38 AM
|
#3
|
LQ Muse
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,639
|
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
|
|
1 members found this post helpful.
|
06-25-2012, 07:00 AM
|
#4
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,799
|
probably you can try nmap and look for ssh port.
|
|
|
06-25-2012, 08:45 AM
|
#5
|
Senior Member
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144
|
NMAP would be more accurate if used:
Code:
nmap -p22 IP_address_of_host (or hostname/domain)
$ nmap -p22 example.com
Starting Nmap 5.61TEST2 ( http://nmap.org ) at 2012-06-25 15:38 CEST
Nmap scan report for example.com (1.5.3.13)
Host is up (0.014s latency).
PORT STATE SERVICE
22/tcp open ssh
Nmap done: 1 IP address (1 host up) scanned in 0.18 seconds
then if you want to know if it's opened, just "grep" output:
$ nmap -p22 example.com | grep open
22/tcp open ssh
|
|
|
06-25-2012, 10:15 AM
|
#6
|
LQ Newbie
Registered: Jun 2012
Posts: 2
Original Poster
Rep:
|
Quote:
Originally Posted by John VV
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
|
i am working on a project on remote administration for class room environment
|
|
|
06-25-2012, 04:04 PM
|
#7
|
LQ Muse
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,639
|
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.
|
|
|
06-25-2012, 04:11 PM
|
#8
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
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 04:00 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|