tags:

views:

32

answers:

3

I created a small script to start openvpn but when I try to execute it i get the following error message and i don't know what i did wrong as i'm not that good with this language:

/etc/init.d/ovpn start
Options error: Unrecognized option or missing parameter(s) in [CMD-LINE]:1: cd (2.1.0)
Use --help for more information.

Here's my code:

#!/bin/sh -e

CONFIG_DIR=/etc/openvpn


start_vpn () {
    # load the firewall
    $CONFIG_DIR/firewall.sh

    # load TUN/TAP kernel module
    modprobe tun

    # enable IP forwarding
    echo 1 > /proc/sys/net/ipv4/ip_forward

    openvpn --cd $dir --daemon --config server.conf
}
stop_vpn () {
    killall -TERM openvpn
}

case "$1" in
start)
  start_vpn
  ;;
stop)
  stop_vpn
  ;;
restart)
  stop_vpn
  start_vpn
  ;;
*)
  echo "Usage: $0 {start|stop|restart}" >&2
  exit 1
  ;;
esac

exit 0

# vim:set ai sts=2 sw=2 tw=0:
A: 

I don't see anything wrong with the script. It looks like an error from the openvpn program who does not recognize the --cd option in the argument list. Check if your openvpn program supports this option.

Stefano Borini
that seems to be it. Thank you
Rob Ian
+2  A: 

$dir seems not to be initialized, causing the --cd option to openvpn to fail (directory not specified).

Diego Sevilla
Yep, you are right.
Stefano Borini
A: 

Try changing your shebang to #!/bin/bash. Also try to find out what $dir since i don't see it declared

ghostdog74