problems writing script to turn off remote computers using ssh
Linux - NewbieThis 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.
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.
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.