Crontab is the most common scheduled Task Service in Linux. This article will share with you some experiences on storing linux crontab logs. I hope this article will teach you more.
By default, logs executed in crontab are written in/var/log, for example:
# Ls/var/log/cron *
/Var/log/cron/var/log/cron.1/var/log/cron.2/var/log/cron.3/var/log/cron.4
If there is a log problem, you can refer to the following practices:
Add logs for crontab
Crontab logs are relatively simple. When crond fails to execute the task, it will send an email to the user. It happened that a task was not executed normally on one of our servers, and crond failed to send emails. By reading the mail log, we can see that the disk space is insufficient.
In addition, my colleagues help me add my own logs for the tasks in crontab, which makes it easy to see the cause after an error occurs.
0 6 * ** $ HOME/for_crontab/createTomorrowTables> $ HOME/for_crontab/mylog. log 2> & 1
Output both error output and standard output to mylog. log.
Note: Do not write
0 6 * ** $ HOME/for_crontab/createTomorrowTables 2> & 1> $ HOME/for_crontab/mylog. log
Otherwise, it will be output to the standard output.