views:

255

answers:

1

i need a python script to run open vpn automaticaly but i use sudo for run the open vpn

sudo openvpn --cd /etc/openvpn --config openvpn.conf &

thats my terminal command. i have to give the password for sudo, can i use pexpect to run that command? and i have to get the exit code because i want to know that the openvpn is run succesful or not

thanks

+1  A: 

You can change /etc/sudoers so that openvpn command can be run without giving the password.

yourusername ALL=(all) NOPASSWD: /path/to/openvpn

and in python, do something like:

import subprocess
exitcode = subprocess.call(["sudo","openvpn","--cd /etc/openvpn --config openvpn.conf"])
Kimvais