![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Checking availability of Web pages through Unix script | srivsn | Shell Programming and Scripting | 6 | 05-30-2007 08:57 AM |
| Transfer file from local unix server to remote server | indira | Shell Programming and Scripting | 2 | 05-03-2007 06:35 AM |
| Transfer file from local unix server to remote server | indira | HP-UX | 2 | 05-02-2007 05:15 PM |
| Checking for availability of remote server | dylanmilks | IP Networking | 1 | 02-22-2007 07:48 PM |
| FTP multiple files from remote server to local server | berlin_germany | Shell Programming and Scripting | 2 | 12-20-2006 03:24 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 to the SSH command to return a true/false indicating success or failure, that's it. One inportant point: PING is disabled in my environment. |
|
||||
|
For cases where
>server is not up and running >DNS could not resolve the server name to IP ssh would come back with a error status and a message of unknown service or name for case >invalid user name if you are using passwordless ssh, number of attempts would be exhausted and returned with an error status if you are using ssh prompted by password, then for an invalid user then you get permission denied each time for case >invalid remote dir clearly ssh would return error status, which could be checked from $? |
|
||||
|
Thanks. The answer came from a reply found in the IP Networking for Dummies newsgroup.
The solution I found was to first run the SSH command, without the `` around it. Then get the return value. For some reason, if I put `` around the SSH command, I can't get the return code. For example: ssh $USER@$SERVER ls -l $FOLDER RESULT=$? If the value of $RESULT is anything other than 0, the command failed. However, the following will NOT work: RESULT=`ssh $USER@$SERVER ls -l $FOLDER` I don't understand why the second example won't work, but it doesn't. |
|
||||
|
Quote:
With the above, only the result returned by executing ls -l $FOLDER would be stored in RESULT var and not the exit status of ssh, need to use echo $? only after ssh executes and returns |
|
||||
|
The above example does what I need it to do. If the DNS name is invalid, it returns 255. If the username is invalid, it returns some other number. If the folder path is wrong, it returns yet another different number. If everything is correct, it returns 0. That's all I need it to do. If the return code is 0, then I proceed with running the "real" command that returns me file count in that folder. So, everything is working as I need it to. Thanks!
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|