Crontab task does not work, Linux, Debian
Solution 1:
Why doesn't it work?
Because there are two slightly different crontab formats, and you used the wrong one – there is no "username" field in per-user crontabs.
Only the system crontab at /etc/crontab
has a "username" field, but the crontabs edited via crontab -e
don't have one, as the whole crontab file already belongs to a specific user (selected using the -u
option).
So in your case, the word root
is being interpreted as the command to run.
When I do
ls -l
in the usr/bin folder I see the following:lrwxrwxrwx 1 root root 21 Dec 15 18:28 php -> /etc/alternatives/php
.
What doesphp -> /etc/alternatives/php
mean ?
It's a symbolic link as the l
character indicates, and the path following ->
is the link's target.
Debian allows several PHP versions to be installed side-by-side (e.g. php8.0
, php7.4
, php7.0
) and has the "update-alternatives" system to choose which version should be the "primary" PHP version. It works by having a chain of symlinks that the "update-alternatives" points to one specific version.
/usr/bin/php7.0
/usr/bin/php --> /etc/alternatives/php --> /usr/bin/php7.4
/usr/bin/php8.0
When saving in GNU nano it prompts to save into the strange file name like the following
/tmp/crontab.AoPJy1/crontab
. Is it correct ?
Yes, that's how the crontab
tool works – it makes a temporary copy of the crontab for you to edit. When the editor exits, the 'crontab' tool moves the temporary file back into its regular location at /var/spool.
Where can I see any logs of crontab runs/errors?
The system log is usually available through journalctl -b
or journalctl -b -u cron
.
It may also be available in the file /var/log/syslog
.