Hi,
I need to create a script (on a linux environment) that does:
- launch the openvpn client up (openvpn remote_factory.ovpn);
- when the openvpn is up, execute a script on the local server that brings some datas on the "ovpnenned" remote server (/bin/sh somescript.sh);
- when the execution og the script is finished, stop the ovpn (thought killall openvpn or something better).
I tryed ti find informations almost everywere, probably someone did it but I can't find infos.
I also know I can do all with a coule of scripts and semaphore technics, but if I can do this more simple is better than playing with files...
Thanks for everyone that can help on it!
REgards,
JS
Openvpn and shell script
Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech
Forum rules
Please use the [oconf] BB tag for openvpn Configurations. See viewtopic.php?f=30&t=21589 for an example.
Please use the [oconf] BB tag for openvpn Configurations. See viewtopic.php?f=30&t=21589 for an example.
-
- OpenVpn Newbie
- Posts: 3
- Joined: Thu Nov 18, 2010 10:58 am
Re: Openvpn and shell script
I would go for something like
/etc/rc.d/openvpn start ( o service openvpn start depending on the version of linux you have).
rsh myremoteserver /home/martin/myscript.sh
/etc/rc.d/openvpn stop.
Of course you can add checks like a loop until its finished and the call the stop.
/etc/rc.d/openvpn start ( o service openvpn start depending on the version of linux you have).
rsh myremoteserver /home/martin/myscript.sh
/etc/rc.d/openvpn stop.
Of course you can add checks like a loop until its finished and the call the stop.
-
- OpenVpn Newbie
- Posts: 4
- Joined: Thu Nov 18, 2010 11:35 am
Re: Openvpn and shell script
Hi, Thanks for the answer.
The problem of using daemon (/etc/init.d/openvpn start|stop) is that in this server there are many ovpn confs, so I must start the openvpn like how I wrote, "openvpn remote_factory.ovpn"... on non daemon method...
This is the problem.
Regards,
JS
The problem of using daemon (/etc/init.d/openvpn start|stop) is that in this server there are many ovpn confs, so I must start the openvpn like how I wrote, "openvpn remote_factory.ovpn"... on non daemon method...
This is the problem.
Regards,
JS
-
- OpenVpn Newbie
- Posts: 4
- Joined: Thu Nov 18, 2010 11:35 am
Re: Openvpn and shell script
Hi,
some other news:
I tried both this methods, but non luck:
openvpn --up 'script_to_run.sh' --config factory.ovpn --script-security 3
and
openvpn --route-delay 10 --route-up 'script_to_run.sh' --config factory.ovpn --script-security 3
In the first example, the routes are not added, and the execution of the script fails; on the 2nd, the routes are added but the initialization isn't completed, so the script fails also.
If someone have any idea... thanks...
Regards,
JS
some other news:
I tried both this methods, but non luck:
openvpn --up 'script_to_run.sh' --config factory.ovpn --script-security 3
and
openvpn --route-delay 10 --route-up 'script_to_run.sh' --config factory.ovpn --script-security 3
In the first example, the routes are not added, and the execution of the script fails; on the 2nd, the routes are added but the initialization isn't completed, so the script fails also.
If someone have any idea... thanks...
Regards,
JS
-
- OpenVpn Newbie
- Posts: 4
- Joined: Thu Nov 18, 2010 11:35 am
SOLVED Re: Openvpn and shell script
Hi,
I respond again to myself: i solved using the --daemon option.
I did a simple bash script where first i create the connession ovpn:
after, e sleep for be sure that everything is ok:
after, I execute the script:
And at the end, I kill the openvpn process;
Everything ok.
Regards,
JS
I respond again to myself: i solved using the --daemon option.
I did a simple bash script where first i create the connession ovpn:
Code: Select all
openvpn --config remote_firm.ovpn --daemon;
Code: Select all
sleep 10;
Code: Select all
./execute_script.sh
Code: Select all
killall openvpn;
Regards,
JS
- krzee
- Forum Team
- Posts: 728
- Joined: Fri Aug 29, 2008 5:42 pm
Re: SOLVED Re: Openvpn and shell script
in that case
hope that helps
(you may need to install pkill)
Code: Select all
#!/path/to/bash
openvpn --writepid remote_firm.pid --daemon --config remote_firm.ovpn
sleep 10
./execute_script.sh
pkill -F remote_firm.pid
(you may need to install pkill)