0

I'm new to freeBSD. I just set up a server and installed python 3.6. Now i want to have a python script run every day at 15h00, so i tried to set up a cron task. But in some way, the cron task never runs or is giving me errors. Since cron uses mail to report errors and mail doesn't seem to be installed on my server, I have no clue whether the script actually runs or is not running at all. The line added in /etc/crontab is the following:

0 15 * * * root /usr/local/bin/python3.6 /root/myscript.py

Where /usr/local/bin is the directory where python is installed. When running this command in the normal command line, it works perfectly, but with cron, it keeps not working. Any help is welcome

Thanks in advance

jb4096
  • 1
  • 3
  • 1
    Have you tried issuing `/usr/local/bin/python3.6 /root/myscript.py` on it's own? also you should be able to read the cron log in `/var/log/cron` to see if it's running. – AndyReifman Mar 14 '18 at 18:03
  • Hi Eabryt, Issueing it on it's own works perfectly, and there seems to be no file called cron in the /var/log folder on my server. – jb4096 Mar 14 '18 at 18:26
  • Why does that crontab line have the word `root` as the first part of the command? – ottomeister Mar 14 '18 at 22:41
  • Hi ottomeister, the "root" i specified there refers to the user with which the script should be executed, the documentation told me that you have to specify the username after the day_of_week – jb4096 Mar 15 '18 at 07:43
  • How did you determine that the cron task never runs or is giving errors? What are the error messages? – Erik Cederstrand Mar 15 '18 at 10:20
  • The script is made such that it should send me an email when there's an error during the execution, but i never receive one. Also i can see that the script is not executed since it doesn't fulfill its task. Also crontab is giving me no errors, so i'm not sure if it runs or not, and if it runs, i don't know for which reason it fails. – jb4096 Mar 15 '18 at 10:47

1 Answers1

3

To debug your environment add this to /etc/crontab

* * * * * root env > ~/cronenv

Wait for file ~/cronenv to be created (after a minute) and start a new shell using does environments:

env - `cat ~/cronenv` /bin/sh

Then call your script /usr/local/bin/python3.6 /root/myscript.py

This will help to test/debug your code within the same environment cron is using.

nbari
  • 25,603
  • 10
  • 76
  • 131
  • Thanks a lot, will try it as soon as i'm back at my server. – jb4096 Mar 15 '18 at 10:48
  • Just tried out the command, seems that even this command is not working in the shell cron uses, the file ~/cronenv is not created. I'll try changing the shell of cron to the shell the root user uses. – jb4096 Mar 18 '18 at 13:11