1

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:

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Always quote variables when using them as a command argument. openvpn --cd "$dir" --daemon --config server.conf
0

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.

1 Comment

that seems to be it. Thank you
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.