Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    .sh Permission Denied

    Scheduled Pinned Locked Moved Development
    5 Posts 2 Posters 4.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      wes93
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • jimpJ
        jimp Rebel Alliance Developer Netgate
        last edited by

        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)

        Remember: Upvote with the ๐Ÿ‘ button for any user/post you find to be helpful, informative, or deserving of recognition!

        Need help fast? Netgate Global Support!

        Do not Chat/PM for help!

        W 1 Reply Last reply Reply Quote 0
        • W
          wes93 @jimp
          last edited by wes93

          @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/

          1 Reply Last reply Reply Quote 0
          • jimpJ
            jimp Rebel Alliance Developer Netgate
            last edited by jimp

            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.

            Remember: Upvote with the ๐Ÿ‘ button for any user/post you find to be helpful, informative, or deserving of recognition!

            Need help fast? Netgate Global Support!

            Do not Chat/PM for help!

            1 Reply Last reply Reply Quote 0
            • W
              wes93
              last edited by wes93

              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.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.