Linux: VPNC Restart Script

The VPN at my company is very… spotty… at best. When working from home, it used to boot you about once every hour. For whatever reason though, it has recently started booting sessions every five minutes. Now, the solution is of course to speak with our networking folks rather than to write a script to fix the issue on a client by client basis. Unfortunately, due to the culture and various political situations, the networking folks will not fix this because they don’t believe it’s an issue. All opinionattion aside, this sounds like an opportunity for a nice shell script.

To start things off, on my Linux box I use vpnc from the command line as I don’t want to install network manager due to additional resource consumption (albeit a very small amount). That said, throw the following script in /bin/vpnconnect and include /bin in your PATH variable (export PATH=~/bin:${PATH}).


Edit: Found a pretty sizeable flaw in my script. Pulled the source until I can sort it out.

Order of Operations

  1. Check if vpnc is already running

    • Start if it is not running

  2. Start an infinite loop

  3. Sleep 5 to keep from using too many resources

  4. Check cpu time on pid - if it is greater than 1 minute

    • Kill pid and restart vpnc

Category:Linux Category:Drafts