Cron Job Save Output to a Log File

Last updated on Jan 2, 2020 in Linux

When the cron job runs, it outputs the script’s result to the standard output (STDOUT) or standard error (STDERR). If you want to save both the output and errors to a log file, this tutorial tells how to do it.

Open Crontab

Open the crontab with your preferred text editor:

$ vim /etc/crontab

Redirect Output to Log File

Add output redirection to the end of the line:

* * * * * /home/user/ >/home/user/myscript.log 2>&1
  • >/home/user/myscript.log tells the cron to send all output (STDOUT) to the file. It always appends the new output to the file.
  • 2>&1 tells the cron to send errors (STDERR) to same target than normal output (STDOUT)

Now, after each cron job execution, you will see output and error in the log file. If you don’t see the file at all, you might try to create an empty file first. Also, check permissions.