Checking for availability of remote server

Hi. In my KSH script I'm running a command on a remote server. I want to know how I can test to see if the remote server is available (accessible) prior to running the command. Any ideas?

My command looks like:

`ssh $USER@$TARGET_SERVER_DNS ls -l $REMOTE_FOLDER `

This check should be generic enough to handle the following cases:

  • server not available (network problem)
  • server DNS name not found
  • invalid user name, user doesn't exist on the remote server
  • remote folder path doesn't exist
  • etc

I just need for the SSH command to return a true/false indicating success or failure, that's it.

One inportant point: PING is disabled in my environment.

As a general rule, if a command does not return an exit status of 0, it means that something failed. I tried out the first four of your scenarios, and ssh returns 255 for the first three error conditions, and returns 2 (file not found) if the remote directory does not exist.

Simply put, check for the return values for the ssh command.