Explore Courses Blog Tutorials Interview Questions
0 votes
in Linux by (18.4k points)

I have the 5 Solaris servers present across different locations. Sometimes some of the servers are not reachable from the location due to various reasons (either because of network problems or this server itself goes down suddenly).

So I would like to write the Bash shell script to check whether they are reachable. What I tried is:

ssh ipaddress "uname -a"

Password-less authentication is set. If I don't get an output I will generate a mail.

  1. Are there any other ways to check server reachability?
  2. What is the best way?
  3. Is it something I have tried to correct?

1 Answer

0 votes
by (36.8k points)

You can use the ping -c4 $ip_address where the $ip_address is IP of your remote server and parse this output to capture these successful packets and/or failed packets and use mail -s to send each log via email.

Here is something to get started and you can build on it.

ping -c4 | awk '/---/,0'

This will give the output like this -

[jaypal:~/Temp] ping -c4 | awk '/---/,0'

--- ping statistics ---

4 packets transmitted, 4 packets received, 0.0% packet loss

round-trip min/avg/max/stddev = 36.638/36.870/37.159/0.196 ms

I checked this Solaris man-page for a ping. The output from ping on a Solaris box is different. Also, on Linux, you limit packets by stating -c and several packets. On Solaris, you would have to do -

ping -s 2 4

/usr/sbin/ping -s [-l | -U] [-adlLnrRv] [-A addr_family]

[-c traffic_class] [-g gateway [ -g gateway...]] [-

F flow_label] [-I interval] [-i interface] [-P tos] [-

p port] [-t ttl] host [data_size] [npackets]

                           ^           ^

                           |           |


Unfortunately, I don't have the Solaris box handy to help you out with.

Want to be a Linux expert? Come and join this Linux course

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jan 6, 2021 in Linux by blackindya (18.4k points)

Browse Categories