Score:1

CRON/crontab does not log errors?

be flag

Is there a way to see if there are any errors when crontab job is executed?

I purposely added a command that returns error so I can check if I'm able to see the error.

*/1 * * * * cd /home/dirthatdoesnotexist && echo "RUNNING" > /tmp/cronlog.log 2>&1

When I call it manually:

milano@milano-desktop:~$ cd /home/dirthatdoesnotexist && echo "RUNNING"
bash: cd: /home/dirthatdoesnotexist: No such file or directory

It returns error as the directory doesn't exist.

But I can't see the error when it's called by CRON.

I checked /tmp/cronlog.log which does not exist. I also checked /var/log/syslog which says that the command has been executed, but it doesn't show the error.

milano@milano-desktop:~$ tail /var/log/syslog

Dec  7 20:12:01 milano-desktop CRON[64936]: (milano) CMD (cd /home/dirthatdoesnotexist && echo "RUNNING" > /tmp/cronlog.log 2>&1)
Dec  7 20:12:01 milano-desktop CRON[64935]: (CRON) info (No MTA installed, discarding output)

Is there a place where the error is logged?

Milano avatar
be flag
I checked `cronlog`.. that was a mistypo. I've removed the `> ...` from `crontab` so it's `*/1 * * * * cd /home/dirthatdoesnotexist && echo "RUNNING"` and I still can't see the error so I don't know what you meant by that.
cn flag
please do not misuse /home/ It is ONLY for users. and also use `>>` to append; `>` will overwrite old log file. The `&&` is only activated on success not on an error. This is probably what you want `*/1 * * * * cd /home/dirthatdoesnotexist >> /tmp/cronlog.log 2>&1 && echo "RUNNING"`
hr flag
You're only redirecting the output/errors of the second command in the conjunction; try *command grouping*: `{ cd /home/dirthatdoesnotexist && echo "RUNNING"; } > /tmp/cronlog.log 2>&1` (a subshell would work as well).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.