|
|
2007-08-15
, 09:00
|
|
|
Posts: 91 |
Thanked: 25 times |
Joined on Mar 2007
@ Marlow, Bucks
|
#2
|
|
|
2007-08-15
, 11:37
|
|
Posts: 2,152 |
Thanked: 1,490 times |
Joined on Jan 2006
@ Czech Republic
|
#3
|
Here's a suggestion:
Write a script to start OpenVPN with the config file you want, call it vpn, and place it in your path. Then, once you are root, you can simply type vpn to start up OpenVPN with your chosen config file.
#!/bin/sh # use gainroot to become root and relaunch itself if [ `id -u` != 0 ] ; then #if not already root, call itself as root TTY=`tty` [ "$TTY" = "not a tty" ] && unset TTY exec sudo gainroot <<EOF if [ -z "$TTY" ] ; then exec $0 $* ; else exec <$TTY $0 $* ; fi EOF exit $? fi # real script follows
|
|
2007-08-16
, 06:10
|
|
Posts: 3 |
Thanked: 0 times |
Joined on Aug 2007
|
#4
|
Well that just rocks. Thanks for the script header and tips on scripting a solution. I wrote a couple of scripts to shortcut a couple of tasks. One was launching openvpn and the other mounting a network share. I have to connect to several windows servers on a daily basis via rdc over vpn so I decided to get fancy and added commandline params to my scripts, then created an alias for each server that invokes the script and passes the relevant params for the particular server. Same thing for the network share mounting too.|
|
2007-08-16
, 07:01
|
|
Posts: 2,152 |
Thanked: 1,490 times |
Joined on Jan 2006
@ Czech Republic
|
#5
|
I was wondering if it was possible to externalize the header to gain root access and then include it somehow, or better create a standalone script that establishes root access and exec that at the start of any script needing root acccess...but seeing as this gains root first, then relaunches itself....that may not be possible because of the recursive nature.?
#!/bin/sh # use gainroot to become root and relaunch itself if [ `id -u` != 0 ] ; then #if not already root, call itself as root exec sudo gainroot <<EOF exec $0 $* EOF exit $? fi # real script follows
#!/bin/sh if [ `id -u` != 0 ] ; then exec sudo gainroot <<E exec $0 $* E ; fi
#!/bin/sh [ `id -u` != 0 ] && exec sudo gainroot <<E exec $0 $* E
| The Following User Says Thank You to fanoush For This Useful Post: | ||
|
|
2007-08-16
, 22:58
|
|
Posts: 3 |
Thanked: 0 times |
Joined on Aug 2007
|
#6
|

All I am trying to do is create an alias that will launch openvpn. Can't do this from the /home/user/.profile because openvpn needs root access.
I have tried editing the /root/.profile and also the /etc/.profile but still no luck. Could anyone point me in the right direction for setting up aliases that will be available within the gainroot environment?
clark