Navigation

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

    [SOLVED] Why doesn't cron run sometimes?

    pfSense Packages
    1
    2
    1062
    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.
    • D
      deajan last edited by

      Just a small post for people like me going nuts for why cron tasks sometimes don't run.

      First, the shebang of your script. I use to have bash scripts that have

      #!/usr/bin/env bash
      

      If your shebang doesn't look like the following it won't execute (giving exit code 127 to cron who doesn't seem to log this anywhere):

      #!/usr/bin/env sh
      

      Your script should reside in /usr/local/bin/script.sh
      Also, render it executable

      chmod +x /usr/local/bin/script.sh
      

      Using the cron packages, it modifies the /etc/crontab file.
      You should not edit this file, but for test sake, you may include a line (put it somewhere between the other lines) that looks like:

      */1     *       *       *       *       root    /usr/local/bin/script.sh
      

      the */1 says it should run every minute.

      NetPOWER.fr - some opensource stuff for IT people

      1 Reply Last reply Reply Quote 0
      • D
        deajan last edited by

        As I have a bash only script, here's a way to get it executed right.

        Create the following script in /usr/local/bin/script-launcher.sh

        #!/usr/bin/env sh
        
        echo "Executing the cron" >> /tmp/cron_test
        PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin /usr/local/bin/obackup.sh /etc/obackup/host_backup.conf
        echo "Return code $0" >> /tmp/cron_test
        
        

        In my case, I have to execute /usr/local/bin/obackup.sh and a parameter, so just replace it with whatever bash script you need to execute.
        Then you can add it to the cron package like:

        
        */1     *       *       *       *       root    /usr/local/bin/script-launcher.sh
        
        

        You may see if it's well executed by using

        
        cat /tmp/cron_test
        
        

        If everything went well, comment out the echos.

        NetPOWER.fr - some opensource stuff for IT people

        1 Reply Last reply Reply Quote 0
        • First post
          Last post