Lesson learned - /etc/crontab

Issues related to applications and software problems and general support
Post Reply
lightman47
Posts: 1521
Joined: 2014/05/21 20:16:00
Location: Central New York, USA

Lesson learned - /etc/crontab

Post by lightman47 » 2021/09/18 16:31:47

After all the years of using /etc/crontab, I just learned:

The last command in the crontab MUST end with a new line character! If it does not, two things go wrong:
* The last command never does run!
* Cron doesn't send it's usual mail to root about ANY job run. I suspect that instead of ending, cron just
'falls out of the bottom' of the file without realizing it ended.

:oops:

pjsr2
Posts: 614
Joined: 2014/03/27 20:11:07

Re: Lesson learned - /etc/crontab

Post by pjsr2 » 2021/09/19 16:25:15

POSIX defines a line in a text file to end with a <newline>, which implies that a text file ends with a <newline>.
See https://pubs.opengroup.org/onlinepubs/9 ... tag_03_206.

This is a very useful property of a text file. Think for example what would happen when you concatenate two text files and the first file does not end with a <newline>. And, what would happen if the last line did not end with a newline for a file that is #include-ed file in a C-source file?

Unfortunately, there are a lot of bad text editors out there that let you create a file without a newline at the end without at least warning you. There may be some cases where it is useful not to end with a newline, but these cases are really the exception. In at least 99 out of 100 cases it is wrong.

BShT
Posts: 583
Joined: 2019/10/09 12:31:40

Re: Lesson learned - /etc/crontab

Post by BShT » 2021/09/20 13:03:57

i allways insert a new line at end of any script

lightman47
Posts: 1521
Joined: 2014/05/21 20:16:00
Location: Central New York, USA

Re: Lesson learned - /etc/crontab

Post by lightman47 » 2021/09/20 15:34:51

I usually do, but on this one machine a job wouldn't run. I edited, noticed & corrected the lack of the newline. Viola - it all starting working again. I've no idea how I managed to enter it originally.

Post Reply