I'm testing stability of a machine and I need way to simply write a Bash script to determine if a host is online or not. How could I script this?
if [ ! $(hostisonline) ]; then
# profit
fi
|
I'm testing stability of a machine and I need way to simply write a Bash script to determine if a host is online or not. How could I script this?
|
|||
|
|
|
A simple solution would be:
where -w specifies a timeout in seconds. |
|||
|
|
|
If the host answers ping then test if its on line by (just an example):
If pings are not returned/forbidden, I'd check for individual services through nmap:
For example to test if ssh is expected to be opened, replace known_port by 22 as for the script it could be (the example -- it's Sunday morning and I'm bored so it has grown a bit after some edits -- is aimed for testing a bunch of hosts, not just one):
When executed it returns (fake ips, so servers are down):
|
||||