In this guide, we will walk you through how to create, enable, and manage cron logs in Linux.
In Linux, cron jobs are planned tasks that run automatically at scheduled intervals. Cron tasks are simple to create, but in order to troubleshoot and make sure everything goes as planned, logs must be kept of their execution.
Follow the article:
Where are cron logs stored in Linux?
- Cron logs are typically stored in the following locations, depending on your Linux distribution:
- CentOS/RHEL:
/var/log/cron
- Ubuntu/Debian:
/var/log/syslog (cron logs are included here)
- CentOS/RHEL:
- Use the following command to view cron logs:
# For CentOS/RHELsudo tail -f /var/log/cron
# For Ubuntu/Debian
sudo grep CRON /var/log/syslog
Enable Cron Logging
Enable cron logging if it is not already active by verifying its status through “rsyslog”.
- Open the rsyslog config file:
sudo nano /etc/rsyslog.conf
- Ensure the following line is uncommented to enable cron logging:
cron.* /var/log/cron
- Save and exit, then restart the “rsyslog” and cron services:
sudo systemctl restart rsyslog sudo systemctl restart cron # or crond for CentOS/RHEL
Redirect Cron Output to a Custom Log File
You can log the output of specific cron jobs to a custom log file using output redirection:
* * * * * /path/to/script.sh >> /var/log/myscript.log 2>&1
- >> appends standard output
- 2>&1 also captures the standard error
This is useful for debugging individual cron jobs.
To View and Analyse Cron Logs
- To monitor cron activity in real time:
sudo tail -f /var/log/cron # or /var/log/syslog
- To search for a specific user’s cron activity:
grep username /var/log/cron
- To find failed cron executions (with errors):
grep -i “error” /var/log/cron
Manage Cron Log File Size (Optional)
Cron log files can grow over time. You can manage them using “logrotate”:
- Check if there’s a logrotate config for cron:
cat /etc/logrotate.d/cron
- You can create or edit this file to rotate logs daily/weekly and limit file size.
Cron logging is a powerful way to monitor automated tasks on a Linux server. By enabling logging, redirecting output, and checking logs regularly, you can catch errors early and maintain a healthy system.
For more such informative articles, do visit our kb section regularly.
Using cPanel? Learn How to set up cron jobs in cPanel