How else can I eliminate this cron job?

I've been working (and looking) to get this cron job / python script running for a while now. However, it clearly doesn't work. I'm not sure how else to troubleshoot and I've tried several things I've found here in other SO questions.

script path: /home/phil/cron_jobs/octoStatus.py

I would like the cron to run every minute.

Crontab.txt file:

*/1 * * * * python /home/phil/cron_jobs/octoStatus/octoStatus.py &> octolog.txt

      

octolog.txt should have recorded STDOUT and STDERR information. The output of "sudo tail / var / log / cron"

Jul  3 10:20:00 bsd /usr/sbin/cron[83876]: (root) CMD (/usr/libexec/atrun)
Jul  3 10:20:00 bsd /usr/sbin/cron[83877]: (phil) CMD (python /home/phil/cron_jobs/octoStatus/octoStatus.py &> octolog.txt)
Jul  3 10:21:00 bsd /usr/sbin/cron[83903]: (phil) CMD (python /home/phil/cron_jobs/octoStatus/octoStatus.py &> octolog.txt)
Jul  3 10:22:00 bsd /usr/sbin/cron[83934]: (phil) CMD (python /home/phil/cron_jobs/octoStatus/octoStatus.py &> octolog.txt)

      

It seems to work every minute at will. However, the expected script results are not happening. octolog.txt is not generated either. When I manually run the exact statement shown in the cron log everything works as expected and the octolog.txt file is generated.

I am running this on FreeBSD and I went to look at / var / log / syslog but it doesn't exist. I'm new to FreeBSD, but I'm not sure if it means much in this situation, but I thought I mentioned it.

I'm not sure what other information would be helpful as I am stuck. Thank you. Phil

+3


source to share


2 answers


First, you don't need to run the script every minute */1

. The cron runs every minute by default, so:

* * * * * /path/to/command

      

Then your redirection might be broken. The man page bash

has the format &>

specified in the Standard Output Redirection and Standard Error section, so I'm assuming what you're trying to do. But FreeBSD is /bin/sh

not bash. So:

* * * * * /path/to/command >/path/to/output.txt 2>&1

      

This sends stdout to your file and duplicates stderr to stdout.



This leads us to:

* * * * * python /home/phil/cron_jobs/octoStatus/octoStatus.py > octolog.txt 2>&1

      

Note also in line with man 5 crontab

, you can set a variable MAILTO

in the crontab file that will send output / errors from your jobs to the email address.

Be aware that the PATH used cron

may not include /usr/local/bin

where python is installed. If your octoStatus.py

script includes a shebang, you can execute it directly. Otherwise, you will either have to provide the full path to your binary python

, or add the PATH variable to your crontab (similar to MAILTO mentioned above). In all cases, you can get formatting instructions by reading man 5 crontab

.

+5


source


I would recommend that you write directly to a file from your python script using mode append

.



Also just guessing, but I think you should give the absolute path to the output file as mentioned in the comment, like python home/phil/cron_jobs/octoStatus/octoStatus.py &> /home/phil/cron_jobs/octoStatus/octolog.txt

+2


source







All Articles