Writing a restarting batch job for vpnc

I have a server that runs secured tunnel connection that occassionally times out. When it does the client calls and I log in with putty, kill all ghost vpnc processes then restart the process.

How hard would it be to write a Windows batch job with icon that would do the same? (start putty, login, issue the two commands, and close). That way the client could double click the restart icon rather than call me.

(I know how to get this done in PHP, but was curious about this approach).

I’m assuming this is a Linux server, in which case you won’t need to write a batch to start putty etc - just write a script to run on the server directly that kills all ghost vpnc processes and restarts teh daemon. This can be done with a simple bash script you oculd then run in a cron.

Yeah it’s Linux. And we have one such cron job that runs at 7:25 AM because it invariably goes down overnight and their office opens at 7:30. But the connection drops during the day. I was wondering if there was a way to activate the cron job using a windows batch or some sort that would open a remote connection, log in, run the server bash script and log out. That way I could set up a click to restore connection button.

I’ll probably just do it in PHP and put an icon for it on their webap’s menu.

You don’t need to keep a connection open to a server for a cronjob to run - they run in the background. If you do need to keep the connection then you aren’t using a cronjob properly.

“crontab -e” to edit your crons

man crontab should give you all hte instructions you need.

Hello Michael,

  1. you need to write a simple script with a sequence of commands which stop and start your tunnel. In shell:

cat > restarttunnel.sh << EOF
killall -9 vpnc ; /etc/init.d/vpnc start ; list-your-complete-commans-here

chmod 750 restarttunnel.sh

  1. set ssh key-based authorization - http://www.howtoforge.com/ssh_key_based_logins_putty

  2. check if you can login to your remote server without password (confirm that key based auth works properly)

  3. login to the server, open ~/.ssh/authorized_keys, you will see smt. like
    ssh-rsa AAAAB3NzaC1yc2EAAAADA …

then add to the start of the first line

IP_ADDR - ip address of your customer.

This is just a sketch, ask me directly if you need a complete guide.