cron apparently requires a newline character on its own line at the end of the file
Is this a bug?
No. I created a file with no newline character at the end. Nevertheless Vim (after :set list
) shows $
at the end. It looks like your premise is false, your file is missing a final newline, cron works as intended.
Notes:
-
POSIX requires a trailing newline character to consider any line to be complete.
3.195 Incomplete Line
A sequence of one or more non-<newline> characters at the end of the file.[…]
3.206 Line
A sequence of zero or more non-<newline> characters plus a terminating <newline> character.So the behavior of cron is not just an arbitrary quirk (although the tool might not be that restrictive). For more insight see Why should text files end with a newline?
Vim with default settings will fix the missing newline while saving, unless you tell it not to.
-
To tell whether there is a newline character at the end or not, make a hexdump of the file, e.g.
hexdump the_file
orxxd the_file
. In case of your crontab this may be hard. In my Debian the crontab is/var/spool/cron/crontabs/kamil
, but since I have no access to/var/spool/cron/crontabs/
as a normal user, I cannot justxxd
the file. To overcome this I can use the following trick:EDITOR=xxd crontab -e
There is a newline at the end iff the last byte reports as
0a
.