I want to know how I can see exactly what the cron jobs are doing on each execution. Where are the log files located? Or can I send the output to my email? I have set the email address to send the log when the cron job runs but I haven't received anything yet.
10 Answers
* * * * * myjob.sh >> /var/log/myjob.log 2>&1
will log all output from the cron job to /var/log/myjob.log
You might use mail
to send emails. Most systems will send unhandled cron
job output by email to root or the corresponding user.

- 6,959
- 2
- 24
- 19
-
111Description of what means `2>&1`: http://stackoverflow.com/questions/818255/in-the-bash-shell-what-is-21 – Yamaneko Sep 26 '12 at 14:26
-
8
-
11FWIW, If you want both `stderr` and `stdout` in the log, the `2>&1` has to come after the indirection: `myjob.sh >> /var/log/myjob.log 2>&1` – Dan Lecocq Apr 23 '14 at 17:08
-
1What could I do, if I want every task to be recorded in its own file? i.e I want to get myjob_x.log, myjob_x2.log where xn may be the current datetime of doing the task. – SaidbakR Nov 02 '15 at 01:35
-
4How to insert `YYYY-MM-DD_hh-mm-sec` into output file name, so that every filename is different and kept without rewriting? – Danijel Jan 11 '16 at 13:16
-
Note that you can create the logfile at any location. It doesn't need to be in /var/log/ – sprksh Sep 06 '16 at 09:19
-
10@Danijel https://serverfault.com/a/117365/193377 0 0 * * * /some/path/to/a/file.php > $HOME/`date +\%Y\%m\%d\%H\%M\%S`-cron.log 2>&1 – AnneTheAgile Oct 11 '17 at 22:11
-
@Daniel 0 0 * * * /some/path/to/a/file.php > $HOME/date +\%Y-\%m-\%d-\%H\%M-\%S-cron.log 2>&1 – sneaky Sep 24 '19 at 14:09
-
-
20 0 * * * /some/path/to/a/file.php > $HOME/\`date +\%Y-\%m-\%d`-cron.log 2>&1 **Don't forget the backticks !** It doesn't show up in @AnneTheAgile and @sneaky comments :D – Gabriel Glenn Nov 09 '21 at 14:04
-
1Just shows that comments are a really bad place to ask follow-up questions. – tripleee Nov 16 '21 at 15:49
By default cron logs to /var/log/syslog
so you can see cron related entries by using:
grep CRON /var/log/syslog
https://askubuntu.com/questions/56683/where-is-the-cron-crontab-log

- 13,144
- 12
- 92
- 130
-
1
-
2
-
8
-
2
-
2
-
7Where exactly `cron` is being logged is very system-dependent. There's a separate answer with details about how various logging destinations are configured on Linux systems (or more correctly, systems which use `syslog`). Other systems might have a different way to configure these things. – tripleee Jun 14 '19 at 11:36
There are at least three different types of logging:
The logging BEFORE the program is executed, which only logs IF the cronjob TRIED to execute the command. That one is located in /var/log/syslog, as already mentioned by @Matthew Lock.
The logging of errors AFTER the program tried to execute, which can be sent to an email or to a file, as mentioned by @Spliffster. I prefer logging to a file, because with email THEN you have a NEW source of problems, and its checking if email sending and reception is working perfectly. Sometimes it is, sometimes it's not. For example, in a simple common desktop machine in which you are not interested in configuring an smtp, sometimes you will prefer logging to a file:
* * * * COMMAND_ABSOLUTE_PATH > /ABSOLUTE_PATH_TO_LOG 2>&1
- I would also consider checking the permissions of /ABSOLUTE_PATH_TO_LOG, and run the command from that user's permissions. Just for verification, while you test whether it might be a potential source of problems.
- The logging of the program itself, with its own error-handling and logging for tracking purposes.
There are some common sources of problems with cronjobs: * The ABSOLUTE PATH of the binary to be executed. When you run it from your shell, it might work, but the cron process seems to use another environment, and hence it doesn't always find binaries if you don't use the absolute path. * The LIBRARIES used by a binary. It's more or less the same previous point, but make sure that, if simply putting the NAME of the command, is referring to exactly the binary which uses the very same library, or better, check if the binary you are referring with the absolute path is the very same you refer when you use the console directly. The binaries can be found using the locate command, for example:
$locate python
Be sure that the binary you will refer, is the very same the binary you are calling in your shell, or simply test again in your shell using the absolute path that you plan to put in the cronjob.
- Another common source of problems is the syntax in the cronjob. Remember that there are special characters you can use for lists (commas), to define ranges (dashes -), to define increment of ranges (slashes), etc. Take a look: http://www.softpanorama.org/Utilities/cron.shtml

- 10,828
- 3
- 41
- 60

- 1,058
- 12
- 9
Here is my code:
* * * * * your_script_fullpath >> your_log_path 2>&1

- 12,577
- 3
- 50
- 36
-
">>" means append data to fileright ? what is meaning of "2>&1", full output with error, right ? – Nullpointer Jun 24 '17 at 13:46
-
5Basic redirection questions are best checked in the manual. There is also a metric potrzebie of duplicate questions about these operators here on Stack Overflow. But yes, roughly; `>>` appends and `2>&1` says to send standard error to the same place as standard output. – tripleee Oct 23 '17 at 07:00
-
Shouldn't it be `&>> my_log_file` if you want both STDOUT and STDERR to be logged? If you do `2>&1` I'm under the impression the file would be attempted to be opened twice, and may malfunction (in case the command prints to both stdd out&err), could be wrong. – Chris Vilches May 14 '23 at 07:57
On Ubuntu you can enable a cron.log
file to contain just the CRON entries.
Uncomment the line that mentions cron
in /etc/rsyslog.d/50-default.conf
file:
# Default rules for rsyslog.
#
# For more information see rsyslog.conf(5) and /etc/rsyslog.conf
#
# First some standard log files. Log by facility.
#
auth,authpriv.* /var/log/auth.log
*.*;auth,authpriv.none -/var/log/syslog
#cron.* /var/log/cron.log
Save and close the file and then restart the rsyslog
service:
sudo systemctl restart rsyslog
You can now see cron log entries in its own file:
sudo tail -f /var/log/cron.log
Sample outputs:
Jul 18 07:05:01 machine-host-name CRON[13638]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
However, you will not see more information about what scripts were actually run inside /etc/cron.daily
or /etc/cron.hourly
, unless those scripts direct output to the cron.log (or perhaps to some other log file).
If you want to verify if a crontab is running and not have to search for it in cron.log
or syslog
, create a crontab that redirects output to a log file of your choice - something like:
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
30 2 * * 1 /usr/local/sbin/certbot-auto renew >> /var/log/le-renew.log 2>&1
Steps taken from: https://www.cyberciti.biz/faq/howto-create-cron-log-file-to-log-crontab-logs-in-ubuntu-linux/

- 10,049
- 6
- 51
- 68
-
2Ubuntu 16.04 didn't show any cron log and this information did the trick. – pojda Nov 29 '17 at 16:10
cron
already sends the standard output and standard error of every job it runs by mail to the owner of the cron job.
You can use MAILTO=recipient
in the crontab
file to have the emails sent to a different account.
For this to work, you need to have mail working properly. Delivering to a local mailbox is usually not a problem (in fact, chances are ls -l "$MAIL"
will reveal that you have already been receiving some) but getting it off the box and out onto the internet requires the MTA (Postfix, Sendmail, what have you) to be properly configured to connect to the world.
If there is no output, no email will be generated.
A common arrangement is to redirect output to a file, in which case of course the cron daemon won't see the job return any output. A variant is to redirect standard output to a file (or write the script so it never prints anything - perhaps it stores results in a database instead, or performs maintenance tasks which simply don't output anything?) and only receive an email if there is an error message.
To redirect both output streams, the syntax is
42 17 * * * script >>stdout.log 2>>stderr.log
Notice how we append (double >>
) instead of overwrite, so that any previous job's output is not replaced by the next one's.
As suggested in many answers here, you can have both output streams be sent to a single file; replace the second redirection with 2>&1
to say "standard error should go wherever standard output is going". (But I don't particularly endorse this practice. It mainly makes sense if you don't really expect anything on standard output, but may have overlooked something, perhaps coming from an external tool which is called from your script.)
cron
jobs run in your home directory, so any relative file names should be relative to that. If you want to write outside of your home directory, you obviously need to separately make sure you have write access to that destination file.
A common antipattern is to redirect everything to /dev/null
(and then ask Stack Overflow to help you figure out what went wrong when something is not working; but we can't see the lost output, either!)
From within your script, make sure to keep regular output (actual results, ideally in machine-readable form) and diagnostics (usually formatted for a human reader) separate. In a shell script,
echo "$results" # regular results go to stdout
echo "$0: something went wrong" >&2
Some platforms (and e.g. GNU Awk) allow you to use the file name /dev/stderr
for error messages, but this is not properly portable; in Perl, warn
and die
print to standard error; in Python, write to sys.stderr
, or use logging
; in Ruby, try $stderr.puts
. Notice also how error messages should include the name of the script which produced the diagnostic message.

- 175,061
- 34
- 275
- 318
Use the command crontab -e
, and then edit the cron jobs as
* * * * * /path/file.sh > /pathToKeepLogs/logFileName.log 2>&1
Here, 2>&1
indicates that the standard error (2>
) is redirected to the same file descriptor that is pointed by standard output (&1
).

- 18,169
- 13
- 73
- 107

- 555
- 5
- 10
-
1Be aware that this recreates the logfile every minute. To append to the file you have to use `>> /path/to/file.log` instaed of `>> /path/to/file.log` – void Mar 14 '23 at 11:13
-
1@void did you mean `>> /path/to/file.log` instead of `> /path/to/file.log` ? – Uriahs Victor Mar 23 '23 at 06:37
-
@UriahsVictor That was exactly what I wrote? `>` overwrites the file, while `>>` appends to it. You can read it up in the docs: https://www.gnu.org/software/bash/manual/html_node/Redirections.html#Redirecting-Output – void Mar 23 '23 at 09:29
-
@void I'm aware, but please read your comment again, you have `>>` in both code examples – Uriahs Victor Mar 23 '23 at 17:49
-
@UriahsVictor you are totally right! The lines break exactly so that I've overseen it on my screen. – void Mar 23 '23 at 20:54
If you'd still like to check your cron jobs you should provide a valid email account when setting the Cron jobs in cPanel.
When you specify a valid email you will receive the output of the cron job that is executed. Thus you will be able to check it and make sure everything has been executed correctly. Note that you will not receive an email if there is no output from the cron job command.
Please bear in mind that you will receive an email for each of the executed cron jobs. This may flood your inbox in case your crons run too often

- 69,473
- 35
- 181
- 253

- 1,741
- 1
- 16
- 27
Logging Cron Tasks For each Cron task, you can set up logging in order to record the results of task execution or error messages. For this you can use output redirection operators:
* * * * * /path/to/command >> /path/to/logfile.log 2>&1
In this example, >> /path/to/logfile.log specifies writing command output to the specified log file, and 2>&1 redirects error messages to the same file.

- 11
- 1
Incase you're running some command with sudo, it won't allow it. Sudo needs a tty.

- 11,036
- 9
- 32
- 40
-
5This also depends on the `sudo` configuration. Things which need to run without a way to supply a password should be configured with `NOPASSWD:` in your `sudoers` configuration. – tripleee Oct 23 '17 at 06:58