I'm about to descend into madness over a cronjob I'm trying to set up. I cannot for the life of me (after spending many hours/effort) figure it out, hope you can help.
I have a Python script at /Server/Home/Paul/Sys+Tech/sortphotos/src/sortphotos.py
that takes some params and organizes files in separate/sub-folders.
When I run this script directly it works just fine
I've set up a crontab for the user owning the python script (paul) that looks like this, but does not work
* * * * * echo $(date) "cron works" > /var/log/testingcron
* * * * * /usr/bin/python /Server/Home/Paul/Sys+Tech/sortphotos/src/sortphotos.py -r --sort "%Y/%Y %m" /Server/Multimedia/Photo/+inbox_paul/ /Server/Multimedia/Photo/
#* * * * * /bin/bash /Server/Multimedia/Photo/organize-inbox.sh
some elaboration
I've set
a+rwx
permissions onsortphotos.py
I've added the full path to the python executable and full path to the script
I've checked access/permissions of the source files
I've tried to set up a
organize-inbox.sh
bash-script containing the full execute command as an intermediary to run thesortphotos.py
(commented out third line), also with lost of permissions on the.sh
. This also works when directly running theorganize-inbox.sh
.I've tried to set up the cron for the root user
I picked up some useful advice during my endless online searches, one of which was to test if cron is actually working by writing to a file. That's what the first cronjob is about. It writes a line in testingcron
every minute, and every minute without fail I have a line with timestamp in said file. Unfortunately the second, and third command do not yield the desired result;
I'm looking forward to learning from you what I'm missing/messing up! Thanks, Paul
p.s. I'm running Ubuntu 20.4
%
did not work until now, I'm trying some other things around syntax (whole command in quotes) - I will update as soon as I know more. Also but theescape
-fix should not be necessary when ran via the bash script but that doesn't work either (as far as my reasoning; cron just runs thesh
and from there it's a shell script as any other, but i'm no expert) as you might have guessed :-) – PaulDP Sep 22 '22 at 12:43journalctl -xe -u cron
, and redirecting the cronjob output/errors to a file (> /tmp/cron.out 2>&1
or similar) that you can examine for clues – steeldriver Sep 22 '22 at 12:47sep 22 14:56:01 precision CRON[2769488]: (paul) CMD (/usr/bin/python /Server/Home/Paul/Sys+Tech/sortphotos/src/sortphotos.py -r --sort "%Y/%Y %m" /Server/Multimedia/Photo/+inbox_paul/ /Server/Multimedia/Photo/)
i.e. the command without the escaping backslashes I definitely put in. I also tried wrapping the whole line inback-ticks
. nothing; very strange – PaulDP Sep 22 '22 at 12:59%
characters as literals). If you omit the backslashes, you would see an incomplete command (truncated at the first un-escaped%
) – steeldriver Sep 22 '22 at 13:10/usr/bin/python /Server/Home/Paul/Sys+Tech/sortphotos/src/sortphotos.py -r --sort "%Y/%Y %m" /Server/Multimedia/Photo/+inbox_paul/ /Server/Multimedia/Photo/ 2>/tmp/sortphotos.log
and then check the/tmp/sortphotos.log
file and report any errors you see. Also, you don't needecho $(date) > file
, you can just dodate > file
directly, but that's not what is causing you problems. – terdon Sep 22 '22 at 13:20/var/log/syslog
? – Jos Sep 22 '22 at 13:25user:paul
and it works, the crontab is foruser:paul
and the owner of the folder is alsopaul
– PaulDP Sep 22 '22 at 13:37-rw-r--r--
. These files are 'uploaded' with Syncthing, so that might be the reason for the lack of permissions. But still, when running the python-script directly (and via.sh
) everything works – PaulDP Sep 22 '22 at 13:42other
did not havewrite
permissions for the destination folder (+sub) - when I set this manually, everything worked. Still I'm not entirely happy with the setting/setup that needs write access for other to be able to run a cronjob that is set up under a specific user, maybe I'm wrong. For now, again; thank you all for helping me and (while doing) teaching me how to debug cron @terdon (2>file
) and also @steeldriver for the syntax help. Cheers! – PaulDP Sep 22 '22 at 14:10