LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 08-27-2012, 10:02 AM   #1
Vi_rod
Member
 
Registered: Dec 2011
Posts: 42

Rep: Reputation: Disabled
How to check if a server is up / down if pinging to that machine is not allowed


Hi,
How to check if a server is up / down if pinging to that machine is not allowed ?
should we do ssh and grep the required part in script?? please help
 
Old 08-27-2012, 12:54 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,818
Blog Entries: 14

Rep: Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076
Various methods exist.

If you run "nmap -Pn -sn <hostname>" it avoids ping but attempts to see if the host is up. Output should be something like:

Starting Nmap 5.21 ( http://nmap.org ) at 2012-08-27 13:19 EDT
Nmap scan report for host (x.x.x.x)
Host is up.
Nmap done: 1 IP address (1 host up) scanned in 0.00 seconds

If you run Nagios for monitoring the plugins include a binary called check_tcp and you can specify port 22 for that.
./check_tcp -H host -p 22
TCP OK - 0.001 second response time on port 22|time=0.000778s;;;0.000000;10.000000

Even if you don't run Nagios you can download and build that plugin for use.

I think were it me I'd go with something that just checked to see if the port was responding like the above rather than doing a full ssh login and command run.
 
1 members found this post helpful.
Old 08-31-2012, 02:09 AM   #3
Vi_rod
Member
 
Registered: Dec 2011
Posts: 42

Original Poster
Rep: Reputation: Disabled
Thanks mate!
I totally forgot about NMAP
 
Old 08-31-2012, 08:56 AM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,818
Blog Entries: 14

Rep: Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076
My apologies. I gave some incorrect advice above. The -PN is something I've used to avoid ping when doing full scans with nmap but what it really does is "assume the host is up" so it will always report host is up even if it fails on scanning.

Instead what seems to work after testing is:

Code:
nmap -PS22 -p22 <hostname or IP>
The above tells it to use port 22 for host discovery instead of ICMP (ping) then tells it to only scan for port 22.

Interestingly although the output of nmap will correctly report a host is down using that syntax it still gives a return code 0 as if it succeeded. This means to use it in a script you'd have to test for the text it outputs rather than the return code.
 
Old 09-02-2012, 06:30 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,347

Rep: Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365Reputation: 2365
That's because the rtn code is that of the nmap program (code) itself, not the returned data ie nmap worked fine ... it doesn't know/care whether you consider up or down to be a fail or success.
 
Old 09-03-2012, 12:06 PM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,818
Blog Entries: 14

Rep: Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076Reputation: 1076
Quote:
Originally Posted by chrism01 View Post
That's because the rtn code is that of the nmap program (code) itself, not the returned data ie nmap worked fine ...
Clearly that is the case but IMHO it is a bogus return code Telling me the code of binary ran without giving me some indication as to whether it was successful in doing what I asked it to do is not correct. Clearly it knows it failed given that it does output the text so I don't believe it should give a non-zero exit code. For example if I run "ls test" and the file named "test" doesn't exist I get both an error message and a return code of 2. Does this mean the binary didn't execute? No - it simply means it couldn't find the file I'd specified.

Quote:
Originally Posted by chrism01 View Post
it doesn't know/care whether you consider up or down to be a fail or success.
It should certainly know/care based on what I specified on the command line just as my ls command would. If I had run simply "ls" in an empty directory it would output a line of "total 0" then show a return code of 0 because in THAT case it didn't "know/care" whether I thought an empty directory was bad but in the earlier "ls test" it did "know/care" that I was specifically looking for the file named "test" and gave the appropriate response.

Last edited by MensaWater; 09-03-2012 at 12:08 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
linux how to check if email server machine doing spamming salimshahzad Linux - Server 3 04-28-2010 03:39 AM
windows machine not pinging to linux sunils1973 Linux - Networking 3 07-21-2009 12:38 AM
Machine Check Exception on new Opteron server humbletech99 Linux - Hardware 2 09-21-2006 10:57 AM
not allowed to connect to mysql server on another machine dsids Linux - Newbie 2 05-26-2006 03:36 PM
eth0 is up but not pinging to any machine devilzgaze Linux - Networking 1 03-09-2005 05:48 AM


All times are GMT -5. The time now is 05:05 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration