0

I am one of those who need to use vpnc for a connection with a net. I've tried so many tutorials' example like this, this and this without success. I know decided to write a small script to reconnect after reconnection. my shell scripting is so bad that i don't know how to log what happens on the box. aside that , i just realized that pinging is disable on the machine i need to connect to. How can i go around it? here is my script which is added to crontab to run every 5 minutes

#!/bin/bash

HOST=" 192.168.0.18"

pinging(){
    ping -c6 $HOST
    return $?
}


pinging
RESULT=$?  

case $RESULT in 
    0)
            #ping OK everything is fine
    ;;      
    1) 
            # no reply, meaning the host down then reconnect
            /usr/sbin/vpnc configname
    ;;      
    2)
           ## Misc. ping errors, 
            # don't know what to do here. how do i log this?
   ;;

esac

so to recap, I need:

  1. Be able to go around pinging. Other alternatives?

  2. Be able to log what happens at every run or so

Can anyone help me achieve that?

2
  • Any reason you can't just check to see if vpnc is no longer running?
    – Cry Havok
    Mar 4, 2013 at 11:57
  • 1
    If you can't ping the host at the other end of the VPN, can you ping something else beyond that?
    – Baldrick
    Mar 4, 2013 at 12:33

3 Answers 3

1

I would probably look at something as simple as:

#!/bin/bash
pgrep vpnc
STATUS=${?}

if [ ${STATUS} -ne 0 ]; then
    /usr/sbin/vpnc configname
fi

That will then launch vpnc if it isn't already running.

0

from googling and readind i decided to base the testing on telnet since that's how i test manually on the box. Below is my approach. So Far so Good. Is there any tool to make my log roll daily or something?

Feel free to make suggestions. Thanks

#!/bin/bash
HOST="192.168.0.18" 
    LOGFILE=/var/log/vpnc/configname.log
    exec 3>/dev/tcp/${HOST}/8888
    if [ $? -eq 0 ]
    then
            echo "$(date +%Y-%m-%d:%T) :Telnet accepting connections" | tee -a $LOGFILE 
    else
            echo "$(date +%Y-%m-%d:%T) Telnet connections not possible" |tee -a $LOGFILE
            echo "$(date +%Y-%m-%d:%T) Reconnecting to telnet" | tee -a $LOGFILE
            pid=$(pidof vpnc)
            if test -z "${pid}" 
                    then
                            echo "$(date +%Y-%m-%d:%T) pid is null" | tee -a $LOFGILE
                            echo "$(date +%Y-%m-%d:%T) restarting vpnc" | tee -a $LOGFILE
                            /usr/sbin/vpnc configname | tee -a $LOGFILE
                    else
                            echo "$(date +%Y-%m-%d:%T) vpnc is running but not connected. killing ${pid}" | tee -a $LOFGILE
                            kill -9 ${pid}
                            echo "$(date +%Y-%m-%d:%T) restarting vpnc" | tee -a $LOFGILE
                            /usr/sbin/vpnc configname | tee -a $LOGFILE
                            echo "$(date +%Y-%m-%d:%T) vpnc running with pid: $(pidof vpnc)" | tee -a $LOGFILE

              fi
       fi   
0

I wrote something similar awhile back and it kind of turned into a pet project. It's a 'VPN companion' script (yes, I just made that phrase up) that actively checks the system to determine if something has gone wrong (eg, VPN drops).

http://code.google.com/p/ipcheck/source/browse/ipcheck.sh

It's pretty well commented if you're looking for something to modify for your purpose.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .