May 22, 2023, 1:27pm
For some reason a cronjob-- the first and only for any regular user on this system-- is not being executed.
crond is running, ascertained by “ps -ef” and “systemctr status crond.service”
/etc/cron.deny is empty
Put the username into /etc/cron.allow and did “systemctl restart crond.service”
Ran the command segment of the crontab entry and it worked just as expected. But it doesn’t run from cron.
I thought to look at the error logs, but I don’t know where they are… not in /var/log/.
I’ve set up cron successfully many times over the years, never had such trouble. Help! (Thanks)
May 22, 2023, 1:35pm
Searching for error logs, I tried this:
journalctl -u cron.service
– No entries –
May 22, 2023, 1:41pm
Here’s the whole crontab file:
$ crontab -l
#min hr DayofMonth Month DayofWk cmd
* * * * * /usr/bin/date +"%R" >> /home/user1/cron.out
May 22, 2023, 2:14pm
This should be
May 22, 2023, 3:36pm
Keep in mind that cron is a legacy method, while the recommended way is systemd timers:
May 22, 2023, 3:59pm
Thanks! You’re right. Works much better.
Now I see that the user1 crontab is being read by crond. But no error is reported.
May 22, 2023, 4:06pm
@vgaetera . I’ll take a look at that… later. I’ve got a big crontab I want to install and have running. Some day I’ll switch over to the new way.
May 22, 2023, 4:10pm
Found the problem. For some reason date +“%R” isn’t executing properly within cron. It works fine at the commandline. I changed that to simply “date” and then I got the output. Has to be that cron is mangling the +“%R” for some reason.
I tested your theory and it certainly seems the formatting does not get processed when date is called by cron.
What I also tested was writing a simple script to process the date command you wished, then used cron to call that script. In that way it seems to work as you expected and the output is formatted.
The content of the script is simply
/usr/bin/date '+%R' >> /home/USER/cron.out
May 22, 2023, 9:10pm
@computersavvy that’s always a good alternative.
I played around with the crontab entry and found that cron was horking on the ambersand (&) and so if I backslash-escaped it, it worked as it should. I.e.,
/usr/bin/date “+%R” >> … (there’s supposed to a backslash character right before the percent-sign, but the web software displaying this page isn’t displaying it
It’s kinda messed up that the bash code works in a script, but not in a crontab. I don’t understand why cron can’t handle the ambersand.
Another thing: Why is there no error reported in journalctl under crond when cron is obviously horking on something?
May 23, 2023, 1:38am
& or percent
% is a special character meaning newline in crontab. See
man crontab.5 about the
crontab file format (not to be confused with
man crontab which defaults to section 1, about the
May 24, 2023, 3:01pm
@jn64, you’re right, it’s the percent. Thanks for the catch.