0

I wrote simple server-client OpenVPN config files:

server.conf

dev tun0
ifconfig 10.8.0.1 10.8.0.2

client.conf

dev tun0
ifconfig 10.8.0.2 10.8.0.1
remote 192.168.0.123

which basically is a cleartext OpenVPN tunnel - for now on its ok to me, I just learn it from basics, the point is - yay, it works! :)

I also wrote a tiny simple bash script to automatically run client:

#!/bin/bash
openvpn --config client.conf

and saved as run.sh. Then, wanted to add it to cron to allow client connect to vpn server at the time I want.

I did:

crontab -e
11 5 * * * /home/mirx/run.sh

but I dont see any connected client on server site - does my cron entry work or not? On client site I dont see any new tun interface when I check it with ifconfig. Any ideas?

mirx
  • 159

1 Answers1

2

Update

Your script must use full path to configuration file, as cron daemon does not run as your user (nor from your home directory).

#!/bin/bash
openvpn --config /home/mirx/client.conf

Also make sure you are editing root's cronjob as you need root to connect to openvpn network

Update 2

Also it seems you might have your corn syntax mixed, have this header to help you set it up :

#minute (0-59),
#|      hour (0-23),
#|      |       day of the month (1-31),
#|      |       |       month of the year (1-12),
#|      |       |       |       day of the week (0-6 with 0=Sunday).
#|      |       |       |       |       commands

Old Answer

I recommend placing ampersand (&) at the end to make sure it runs in the background:

11 5 * * * /home/mirx/run.sh &

This way you can check if it is running or kill it if needed with ps ax | grep 'run.sh'

Also, if you are using any variables like $HOME or relative paths in your run.sh script it will not work, as cron is ran as a separate user which usually does not have access to most of your environment variables.

ek9
  • 2,131