Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating a bash script that does checkouts for me using whiptail. I've got it all working but I'd like to check if i can reach svn before showing a menu etc.

Currently I'm going to do svn ls svn://host and check if the responce is equals svn: Unknown hostname 'host'. if so exit / show msg.

Is there a better way to do this using shell commands?

Grtz Michael

share|improve this question
up vote 4 down vote accepted

Your solution seems to be good enough, because if you're going to do checkout, it's guaranteed that svn is installed on the system. So there are no additional requirements only to check if the remote port is open.

However, another possible solution would be to use netcat which is installed on most UNIX-like systems:

#! /bin/sh

TIMEOUT=2 # in seconds

$(nc -z -w ${TIMEOUT} ${HOST} ${PORT}) || \
    exit 1 # Port is closed

# Port is open, continue processing

The benefit from the netcat-based script is that the timeout value prevents us from waiting a lot of time on ports protected with DROP firewall rules.

share|improve this answer
my solution works at the moment but yours looks more promising. Mine feels kinda iffy using substring & string compare. I'll give it a go. – Michael Sep 18 '11 at 12:08
Its working now. I did it like this: – Michael Sep 18 '11 at 12:25
nc -z -w ${timeout} ${host} ${port} 2> $tmp > /dev/null; check=$(<$tmp) if [ "$check" != "" ]; then whiptail --title "Error" \ --msgbox "Svn host [$host] on port [$port] is not reachable" 8 78 exit fi – Michael Sep 18 '11 at 12:25

You shouldn't need to check the command output.. just the status should be sufficient.


svn info ${SVN_URL}
if [ $? -eq 1 ]; then
    echo "svn command failed: unable to access ${SVN_URL}";
    exit 1;

#else continue svn server appears to be ok

The advantage of this is it will also fail on a miss typed url.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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