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

    Cron Package not running command?

    Scheduled Pinned Locked Moved pfSense Packages
    4 Posts 2 Posters 2.3k 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.
    • P
      pfs_noob
      last edited by

      Hi All,

      I have a fully working PF Sense implementation, though I have an issue of undetermined origin, which requires me to bounce my WAN interface occasionally (once every week or two).

      I found a script that I have validated works for this purpose, and I have installed the Cron service, with a view to running it every 5 minutes to check if it can ping outside, and if not, bounce the interface.

      The script works perfectly if I run it from diagnostics –> command prompt (using the command```
      /usr/local/bin/pingtest.sh

      
      The script does not, however, appear to be executed by cron. My cron setup looks like:
      
      ![](http://cron.PNG)
      
      I have also tried chaging the command to```
      sh /usr/local/bin/pingtest.sh
      

      I have executed```
      chmod +x /usr/local/bin/pingtest.sh

      ![cron.PNG](/public/_imported_attachments_/1/cron.PNG)
      ![cron.PNG_thumb](/public/_imported_attachments_/1/cron.PNG_thumb)
      1 Reply Last reply Reply Quote 0
      • jimpJ
        jimp Rebel Alliance Developer Netgate
        last edited by

        When run from Cron, the script won't have a PATH or some other environment variables. Programs called inside the script must use a full path to their executables.

        If you need help checking that, we will need to see the contents of your pingtest.sh script.

        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
        • P
          pfs_noob
          last edited by

          Thanks for the reply. The pingtest script is one that I actually got on here, which seems to be working according to the thread: https://forum.pfsense.org/index.php/topic,17243.msg89348.html#msg89348

          If you prefer not to follow the link, the code is:

          
          #!/bin/sh
          
          #=====================================================================
          # pingtest.sh, v1.0.1
          # Created 2009 by Bennett Lee
          # Released to public domain
          #
          # (1) Attempts to ping several hosts to test connectivity.  After
          #     first successful ping, script exits.
          # (2) If all pings fail, resets interface and retries all pings.
          # (3) If all pings fail again after reset, then reboots pfSense.
          #
          # History
          # 1.0.1   Added delay to ensure interface resets (thx ktims).
          # 1.0.0   Initial release.
          #=====================================================================
          
          #=====================================================================
          # USER SETTINGS
          #
          # Set multiple ping targets separated by space.  Include numeric IPs
          # (e.g., remote office, ISP gateway, etc.) for DNS issues which
          # reboot will not correct.
          ALLDEST="google.com yahoo.com 24.93.40.36 24.93.40.37"
          # Interface to reset, usually your WAN
          BOUNCE=em0
          # Log file
          LOGFILE=/root/pingtest.log
          #=====================================================================
          
          COUNT=1
          while [ $COUNT -le 2 ]
          do
          
          	for DEST in $ALLDEST
          	do
          		#echo `date +%Y%m%d.%H%M%S` "Pinging $DEST" >> $LOGFILE
          		ping -c1 $DEST >/dev/null 2>/dev/null
          		if [ $? -eq 0 ]
          		then
          			#echo `date +%Y%m%d.%H%M%S` "Ping $DEST OK." >> $LOGFILE
          			exit 0
          		fi
          	done
          
          	if [ $COUNT -le 1 ]
          	then
          		echo `date +%Y%m%d.%H%M%S` "All pings failed. Resetting interface $BOUNCE." >> $LOGFILE
          		/sbin/ifconfig $BOUNCE down
          		# Give interface time to reset before bringing back up
          		sleep 10
          		/sbin/ifconfig $BOUNCE up
          		# Give WAN time to establish connection
          		sleep 60
          	else
          		echo `date +%Y%m%d.%H%M%S` "All pings failed twice. Rebooting..." >> $LOGFILE
          		/sbin/shutdown -r now >> $LOGFILE
          		exit 1
          	fi
          
          	COUNT=`expr $COUNT + 1`
          done
          
          

          I haven't modified the script, other than to change the IP addresses for pinging to 8.8.8.8 and 4.4.4.4 (Google nameservers), and to change my WAN interface to re1.

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

            At the very least, ping should be /sbin/ping, and expr should be /bin/expr

            There may be more but I didn't look over every line. You'll need to fix any place that runs a command without specifying the full path.

            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
            • First post
              Last post
            Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.