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.
Lesson learned - /etc/crontab
-
- Posts: 1522
- Joined: 2014/05/21 20:16:00
- Location: Central New York, USA
Re: Lesson learned - /etc/crontab
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.
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.
Re: Lesson learned - /etc/crontab
i allways insert a new line at end of any script
-
- Posts: 1522
- Joined: 2014/05/21 20:16:00
- Location: Central New York, USA
Re: Lesson learned - /etc/crontab
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.