.sh Permission Denied



  • Hello, i want to run a script that is in /home/wes93/ensure_vpn.sh but the shell give me a Permission denied... can someone help me?
    Thanks a lot
    Stefano


  • Rebel Alliance Developer Netgate

    Most likely a basic UNIX file permission/script issue, not specific to pfSense.

    Usual things to check are:

    1. Make sure the file is set executable (chmod u+x /home/wes93/ensure_vpn.sh)
    2. Make sure the shabang line in the script is pointing to a valid interpreter (e.g. /bin/sh)


  • @jimp Thanks a lot for your help!!!
    I have executed in Command Prompt inside the web interface the command chmod u+x /home/wes93/ensure_vpn.sh and now when i run
    env VPN_ID=1 PING_HOST=mit.edu ./ensure_vpn.sh
    the system i think run the script but no response received..
    inside the script there are these settings:

    
    
    #!/usr/bin/env sh
    
    # Ensure OpenVPN connection
    #
    # pfSense script that restarts an OpenVPN client if the VPN is down.  Intended
    # to be run periodically to help ensure that an OpenVPN connections reestablish.
    #
    # Required environment variables:
    #
    #   VPN_ID - the numeric ID of the OpenVPN client
    #   PING_HOST - the host to ping to test if the VPN is alive
    #
    # Find the VPN_ID by running `ifconfig` and looking at the interfaces that start
    # with "ovpnc".  Then set VPN_ID to the number in the interface name.  For
    # example, if the interface is named "ovpnc2" you would set VPN_ID=2.
    #
    # The source IPv4 address is looked up using `ifconfig` and if one exists, then
    # we attempt to ping the host defined at PING_HOST.  If the source address for
    # the VPN interface cannot be found, or the host cannot be pinged, we attempt to
    # restart the OpenVPN client associated with the VPN_ID.
    #
    # Example:
    #
    #   env VPN_ID=1 PING_HOST=mit.edu ./ensure_vpn.sh
    #
    # Example cron:
    #
    #   */5 * * * * root /usr/bin/env VPN_ID=2 PING_HOST=work.com /root/ensure_vpn.sh
    
    if [ -z "$VPN_ID" ] || [ -z "$PING_HOST" ]; then
        echo "Must specify VPN_ID and PING_HOST environment variables"
        exit 1
    fi
    
    # src is the source IPv4 address of the VPN interface
    src=`/sbin/ifconfig ovpnc${VPN_ID} | grep 'inet\b' | awk '{print $2}'`
    
    if [ -n "$src" ] && /sbin/ping -S "$src" -c 3 "$PING_HOST" > /dev/null; then
        # Success, Nothing to do
        exit 0
    else
        # Fail, Reconnect VPN
        /usr/local/sbin/pfSsh.php playback svc restart openvpn client "$VPN_ID"
    fi
    exit 1
    

    I'm Trying to do what i written in this link: https://www.foxypossibilities.com/2018/05/23/reestablish-pfsense-openvpn-clients-with-cron/


  • Rebel Alliance Developer Netgate

    I can't help debug your script. You might try asking the original author of the script for help, or now that you have the script running, try posting in the OpenVPN category here.



  • Really thanks a lot!!! the last question, is there a way to check if Cron work properly like some logs?
    Now the script run correctly i have checked with ssh really thanks a lot!!
    Thanks a lot
    Stefano.