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

    Cron jobs not running

    Scheduled Pinned Locked Moved General pfSense Questions
    4 Posts 2 Posters 1.6k 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.
    • S
      sos
      last edited by

      I have the following command entered under 'cron'. It's designed to download an ad-blocking host file, and update over the previous version if it's found to be newer. It works flawlessly when run as a block command in the shell, but doesn't seem to be running as a cron job i.e. my file "/etc/extra-blocks" isn't updating as it should.

      Under 'cron', the command is as follows:

      /bin/sh -c 'FILE="/etc/extra-blocks" ; /usr/bin/fetch -q -o ${FILE}.new http://someonewhocares.org/hosts/hosts && if [ -s ${FILE}.new ]; then if [ -f ${FILE} ]; then /bin/mv ${FILE} ${FILE}.old ; fi && /bin/mv ${FILE}.new ${FILE} && /usr/local/sbin/pfSctl -c "service reload dns" && if [ -f ${FILE}.old ]; then /bin/rm -f ${FILE}.old ; fi ; fi'

      The cron is scheduled as:
      5  0  *  *  6  root

      Which I think indicates minutes past midnight, every saturday night.

      1 Reply Last reply Reply Quote 0
      • BBcan177B
        BBcan177 Moderator
        last edited by

        You should check out pfBlockerNG which has DNSBL integrated into the GUI…

        https://forum.pfsense.org/index.php?topic=102470.0

        "Experience is something you don't get until just after you need it."

        Website: http://pfBlockerNG.com
        Twitter: @BBcan177  #pfBlockerNG
        Reddit: https://www.reddit.com/r/pfBlockerNG/new/

        1 Reply Last reply Reply Quote 0
        • S
          sos
          last edited by

          @BBcan177:

          You should check out pfBlockerNG which has DNSBL integrated into the GUI…

          https://forum.pfsense.org/index.php?topic=102470.0

          Thanks for the pointer - but hosts files are so resource light :)

          How might I convert the code to a shell script ("update-adblock.sh") which I can then ask cron to run directly?

          1 Reply Last reply Reply Quote 0
          • S
            sos
            last edited by sos

            I finally got the above scripts running as shell scripts, then using cron to call the script itself. So easy and so basic, it's embarrassing to be posting it to such a learned forum, especially after all these years. :)

            The main motivation to finally learn how to script this came via adapting scripts to automate ACME's Let's Encrypt SSL certs into my UniFi controller, which I have running on my pfSense box (https://community.ubnt.com/t5/UniFi-Wireless/Unifi-Cloud-key-certificate-installation/m-p/2437833#M312944)

            Anyway, the basic script to automate adblock hosts file updates is:

            #!/bin/sh
            
            FILE="/etc/adblock"
            /usr/bin/fetch -q -o ${FILE}.new http://winhelp2002.mvps.org/hosts.txt &&
            if [ -s ${FILE}.new ]; then if [ -f ${FILE} ] ; then /bin/mv ${FILE} ${FILE}.old ; fi &&
            /bin/mv ${FILE}.new ${FILE} &&
            /usr/local/sbin/pfSctl -c "service reload dns" &&
            if [ -f ${FILE}.old ]; then /bin/rm -f ${FILE}.old ; fi ; fi
            

            Obviously the file name (FILE) and download source can be easily varied according to need. Simply make the script executable (chmod +x) and then point cron to run it whenever you want.

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