How To Check Connectivity Between Two Servers

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

So I would like to write a Bash shell script to check wether they are reachable. What I have tried is:

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

At any place on the application server desktop Drop Right Click. Select New New Text Document. Rename the file to any appropriate name Change the extension from.TXT to.UDL file. Double click on the created file The Datalink Properties should be shown. Type or select the SQL Server name. Select the authentication mode.

  1. Are there any otherways to check server reachability?
  2. Which one is the best way?
  3. Is what I have tried correct?
Balaswamy VaddemanBalaswamy Vaddeman
6,4553 gold badges23 silver badges38 bronze badges

7 Answers

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

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

This will give an output like this -

I checked the Solaris man-page for ping. Output from ping on Solaris box is different. Also, on Linux you limit the packets by stating -c and number of packets. On Solaris you would have to do -

Unfortunately I don't have a solaris box handy to help you out with.

jaypal singhjaypal singh
59.8k15 gold badges86 silver badges124 bronze badges

Your ssh command will test for more than if the server is reachable - for it to work, the ssh server must be running, and everything must be right with authentication.

To just see if the servers are up, how about just a simple ping?

CoolAJ86
51.5k10 gold badges66 silver badges83 bronze badges
gcbenisongcbenison
7,8441 gold badge30 silver badges66 bronze badges

The most barebones check you can do is probably to use netcat to check for open ports.

to check for SSH (port 22) reachability, you can do

from the manpage:

-z Specifies that nc should just scan for listening daemons, without sending any data to them.

flying sheepflying sheep
4,7004 gold badges36 silver badges55 bronze badges

Check My Connection With Server

You could use these options from the ping man page:

  • only send one packet ('c1'),
  • quiet mode ('q'),
  • (optional) Wait for 1 second for a response ('W1')

    ping -c1 -W1 -q $server

Ping returns different exit codes depending on the type of error.So, to test if it worked or not, just do 'echo $?' to get the exit code. Like this:

Where

So, to test this in a bash script, you could do something like:

KatieKatie
28.2k12 gold badges65 silver badges90 bronze badges

You can use below command,

you can't use $ip_addr as it will remove first number of your IP.

Amit
7,56915 gold badges59 silver badges136 bronze badges
Two

How To Check Connectivity Between Two Servers In Solaris

rocket singhrocket singh

You can use the nc -z -G 2 SERVER_HOST PORT approach with G instead of W -> G being used for timeout before connection established , so it host is unreachable , you'll know faster

Ivo VarbanovIvo Varbanov

Some more food for thought : Use nmap or nc, never ping.

Ping: Why should you not use ping ? (1) It is better to check the system and the port at the same time. (2) Ping is unreliable as icmp echo is blocked in many situations.

Nmap: This is very quick, very reliable but requires nmap to be installedPreferred method NMAP (ex host ip 127.0.0.1) :

Nc: nc is usually installed already , however on some systems such as Mac OS X, the command hangs on unreachable systems. (see workaround)

Mac OSX Workaround :

(examples illustrate connecting to port 22 ssh over a good and bad host example, use the $? to determine if it reached the host with the sleep time of 3 seconds)

For Mac Users (mainly) etc, you can use the command in the script like so :

Mike QMike Q
3,0601 gold badge28 silver badges42 bronze badges

Not the answer you're looking for? Browse other questions tagged bashshellsolaris-10 or ask your own question.