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

    CRON Problem

    Scheduled Pinned Locked Moved General pfSense Questions
    3 Posts 2 Posters 1.8k 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.
    • G Offline
      guardian Rebel Alliance
      last edited by

      Hi All

      Hope someone can help me out here.

      I've written a python script that I want to run under CRON every 5 minutes. 
      In keeping with the general security practice of least privilege, I:

      • created a user "custom" to use for custom scripts

      • created a group "custom" (don't want anything running under nobody to have access) and

      • put the script (monitor) in /home/custom/bin

      The shebang in the script is:
      #!/usr/bin/env python2.7

      The only permission given to user custom is:
      Inherited from Name Description              Action
                      User - System: Shell account access Indicates whether the user is able to login for example via SSH.

      Running the script with the command /home/custom/bin/monitor from the command line works regardless of the current working directory.

      I tried doing cd / first to make sure it wasn't a path issue, and the script ran correctly.

      The script writes 2 files on the first run, and subsequent runs append to those files in the directory /home/custom/bin/mondata

      I installed the CRON package and created the following entry:

      */5 * * * * custom /home/custom/bin/monitor

      (There doesn't seem to be an "Apply Changes", so I'm assuming that I don't need to reboot or do anything to load the changes.)
      (The above entry and many others are displayed in the WebGUI, and I know that several of those other cron jobs are running.)

      After waiting for enough time for the script to run, I checked for output and there was nothing.

      Changing custom to root for testing purposes (Just in case the issue was a permission problem) doesn't fix the problem.

      Here are the relevant file permissions:

      [2.3.2-RELEASE][custom@local]/home/custom/bin: ls -laR ~
      total 52
      drwxr-xr-x  4 custom  nobody  512 Aug  7 00:14 .
      drwxr-xr-x  4 root    wheel    512 Jul 27 15:24 ..
      drwxr-xr-x  3 custom  custom  512 Aug  7 00:14 bin

      /home/custom/bin:
      total 20
      drwxr-xr-x  3 custom  custom  512 Aug  7 00:14 .
      drwxr-xr-x  4 custom  nobody  512 Aug  7 00:14 ..
      drwxrwx–-  2 custom  custom  512 Aug  7 00:07 mondata    <-Script output goes here
      -rwxr-xr-x  1 custom  custom  4663 Aug  5 22:44 monitor    <-The script

      /home/custom/bin/mondata:
      total 8
      drwxrwx---  2 custom  custom  512 Aug  7 00:07 .          <-NO OUTPUT! (I deleted the files manually after successful tests)
      drwxr-xr-x  3 custom  custom  512 Aug  7 00:14 ..

      I checked for an error message in: Status / System / Logs / System / General - Nothing found.

      I even tried temporarily changing the permissions on /home/custom/bin/mondata to 777 and setting the cron user to root
      (totally unacceptable security practice just for testing, but even that didn't work.)

      I have no way of knowing if the script is running and the file writes are being denied for some reason, or if the script isn't running at all.

      BTW, where is the cron tab?  When I run crontab -l as root, I get crontab: no crontab for root, but I KNOW cron jobs are running. 
      (I have the daily mail report running.)

      Any suggestions - even for troubleshooting to know if the script is running would be helpful.

      Thanks.

      If you find my post useful, please give it a thumbs up!
      pfSense 2.7.2-RELEASE

      1 Reply Last reply Reply Quote 0
      • w0wW Offline
        w0w
        last edited by

        If you want to test cron
        */1 * * * * root /usr/local/bin/minicron
        You should receive "minicron Wrong number of arguments passed " every minute is System Logs

        1 Reply Last reply Reply Quote 0
        • G Offline
          guardian Rebel Alliance
          last edited by

          Thanks w0w… very useful, that gave me what I needed to figure it out.

          The issue was that python was not executing.

          The so called "portable" shebang that worked at the command line
          #!/usr/bin/env python2.7 - DOES NOT WORK from cron.

          I created the following file as /home/custom/bin/tcron

          #!/usr/bin/env python2.7
          import os
          os.system('/usr/local/bin/minicron')

          When run from the command line, it put the minicron error into the log every time it is run, but did nothing when run from cron.
          I changed #!/usr/bin/env python2.7 to #!/usr/local/bin/python2.7, and now it works.

          I don't know if this is intentional that #!/usr/bin/env python2.7 doesn't work from cron, but for now I'm not going to worry about it.

          I hope by documenting this it might save somebody else the same trouble, and if it's a bug that should be reported, someone who knows how to do that will do so.

          If you find my post useful, please give it a thumbs up!
          pfSense 2.7.2-RELEASE

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