The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
check ssh connection to remote host praveenbvarrier Shell Programming and Scripting 6 10-06-2008 12:46 PM
How can my unix shell script automatically connect to remote host? digdarshan Shell Programming and Scripting 8 06-29-2007 11:44 PM
How to delete the files from local host to remote host krishna176 SUN Solaris 3 03-24-2007 04:48 PM
Remote SSH Connection Using Script ajith_tg Shell Programming and Scripting 1 07-21-2005 10:42 AM
FTP - Connection Closed By Remote Host mouglybean IP Networking 1 10-26-2004 09:15 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-16-2008
zulfikarmd zulfikarmd is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 16
Bash Script to check Remote Host Connection

Hi all,

Can anyone tell/guide me how to check remote host is up/running using bash script?

Thanks.
Zulfiqar
  #2 (permalink)  
Old 04-16-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Define "up and running".

Code:
ping -c 1 remotehost || { echo "does not respond to ping" >&2 ; exit ; }
rup remotehost || { echo "no rup" >&2; exit; }
# if you have netcat, and ssh on port 22 on remotehost
nc -z remotehost 22 || { echo "nobody home on port 22" >&2; exit; }
ssh remotehost true || { echo "does not let me in" >&2; exit; }
If you want to check port 80 instead, try to fetch a web page, etc.

This obviously also depends on firewall blocks and stuff like that.
  #3 (permalink)  
Old 04-16-2008
zulfikarmd zulfikarmd is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 16
Thanks Era. By "Up and Running" I mean i should be able to scp necessary file from that machine to other machine. Hope this helps.

Thanks again for your help.

Regards.
Zulfiqar
  #4 (permalink)  
Old 04-16-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
By that definition, if your scp fails, it's not.

Code:
if scp remotemachine:path/to/file here/
then
  # it's up and running! whee
else
  echo "could not scp: $?" >&2
  exit $?
fi
You might still want to check if it's responding to ping and accepting connections on port 22 before attempting the actual copy, but in practice, often all you really care about anyway is whether the copy succeeded or not.
  #5 (permalink)  
Old 04-16-2008
zulfikarmd zulfikarmd is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 16
Thanks Era. But this script would just check scp is successful or not. But What I want is to see if remote host is able to accept connection before doing scp.

Thanks.
Zulfiqar
  #6 (permalink)  
Old 04-16-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
If you can ssh, you can scp.
Sponsored Links
Closed Thread

Bookmarks

Tags
ping, ping port, port, port ping

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:58 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0