Ubuntu Create a cron.log File To Log crontab Logs [16.04/18.04/20.04]

Ubuntu Create a cron.log File To Log crontab Logs [16.04/18.04/20.04]

To create a cron.log file to log crontab logs on an Ubuntu system, follow these steps:

  1. Open the crontab configuration file for the root user:
sudo crontab -e
Sourc‮e‬:www.lautturi.com
  1. At the top of the file, add the following line to redirect the output of crontab to the cron.log file:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
* * * * * /usr/bin/php /var/www/html/cron.php >> /var/log/cron.log 2>&1

This will log the output of the crontab command to the cron.log file in the /var/log directory.

  1. Save the file and exit.

  2. To view the cron.log file, use the tail command:

tail /var/log/cron.log

This will display the last few lines of the cron.log file.

Created Time:2017-10-30 14:27:24  Author:lautturi