Crontab and newline

Why the last line in crontab must end with a newline, and what happens if it doesn’t

A surprising issue with cron

Today I noticed that one of the cron jobs wasn’t working on a test server - the email sender. Every morning, a script should send reminder emails about unfinished tasks.

I added the job to crontab two days ago in the evening. But yesterday and today, no emails arrived. At first, I thought the script was broken. I ran it manually - and the emails were sent. Then I checked the cron logs and saw that the script wasn’t being run at all.

What was the mistake

When I looked at the crontab, everything seemed fine: correct format, proper script paths. But the command that didn’t run was the last line in the file.

That’s where I messed up - I forgot to add a newline at the end. In crontab, the last entry must end with a newline. If it doesn’t, cron will ignore that line.

So, after the last command in crontab, there must be an empty line. Be careful and don’t make the same mistake.

Good to know

Cron logs for the previous day are usually found in:

1
/var/log/cron
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy