I would like to check if given server is online and given service is active -- or maybe even simpler, if given port is open.
Something like this:
port_check my_server 22
or
service_check my_server ssh
And I would get a binary answer -- yes/no, meaning everything is OK, or there is no connection (server is down, or the service is not active).
I have to run this tool from ordinary user account (non-root). 开发者_JAVA百科The question is -- what is the tool? Thank you in advance for help.
Edit: please note, I have to get binary answer, which means any interactive tool, or tool that tries to log in first is no good. It should be basically a ping but for any service.
telnet
is that tool. check.sh
#!/bin/sh
telnet -e / $1 $2 <<END
/
close
END
echo $?
running - check.sh localhost <port>
Note that the service listening the port will be touched.
you can also try nmap tool.
the simplest way to use it is nmap -p$2 $1
but you can alternatively specify a port or even a host range to check.
精彩评论