Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What would be the best way of going about the following problem?

I have a server that I periodically dump backups to. The only way to connect to this server is via OpenVPN. So far I tested everything manually and it worked fine. Here's what I do:

  1. run openvpn --config my-server-connection-details.ovpn
  2. in second screen console window I mount NFS share, perform the copy and unmount it
  3. I go back to screen console 1 and ctrl+c the connection.

How can I best script it so I can just put it in cron? I'm mostly inquiring about the openvpn part, as the rest seems clear to me and I'm an OpenVPN / VPN newbie. The client is a linux machine.

Thanks in advance.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

What distribution of Linux? This should be trivial on Debian/Ubuntu.

Setup your config in /etc/openvpn/myvpn.conf, adjust your /etc/default/openvpn file so vpns are not automatically started.

Then your script does something like this. No need to use screen or anything fancy.

#!/bin/sh
/etc/init.d/openvpn start myvpn
mount /nfs
rsync src dst
/etc/init.d/openvpn stop myvpn
share|improve this answer
    
Worked like a charm. Simple and easy. Thank you for your advice! –  Michal Rogozinski Dec 22 '12 at 1:57
add comment

Your Answer

 
discard

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.