Crontab comments on same line as job seem to cause issues

0

Can you put a comment on the same line as a cron job?

Example:

* 19 * * * lnxuser rm /home/lnxusr/edi/logs/mcfg204_`date -d -8days +\%Y\%m\%d`.log #THIS IS TO WIPE A 204 LOG THAT IS OLDER THAN A WEEK

I tried it on a working crontab on an Ubuntu system and it stopped processing crobjobs. Nothing in /var/log/syslog showed any kind of status (only the last successful run). When I put the comment on a line of its own and restarted cron daemon, the issue was solved.

This works fine in bash scripts, so I was a bit shocked by this since I thought crontab was just a script itself.

gregg

Posted 2013-04-03T14:25:09.490

Reputation: 2 025

Answers

1

Well, if it didn't work, then obviously you cannot do it. :)

On a more serious note, I always put comments on separate lines in crontabs. It is essentially guaranteed to work regardless of which cron daemon happens to be in use, and I find it to be much more clear since the comment comes before what it comments.

Remember that there are multiple different cron implementations (a quick check in Debian stable/main shows half a dozen or so), and they may each have slightly different semantics, particularly in such edge cases.

a CVn

Posted 2013-04-03T14:25:09.490

Reputation: 26 553

1Well I wasn't sure & wanted to see if anyone else could give a reference confirming that it shouldn't be done or test it themselves – gregg – 2013-04-03T15:04:08.297