I am trying to troubleshoot why my cron task isn't working sometimes. Where does cron store log files by default? Is it /var/log/syslog ?
I have looked at that file and it is empty. Do I need to set something up?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
As default, cron's logs saved in /var/log/syslog.
It depends on rsyslogd configuration. You can change it:
Go to rsyslog config
sudo nano 50-default.conf
Save file and restart rsyslog
sudo service rsyslog restart
Restart your cron daemon for get it's messages from new file
sudo service cron restart
cron doesn't work, it'll send out a mail to the user
root. The only problem is: you don't have the software to send / store the mail in mailboxes.
But have no fear,
Postfix is here!
sudo apt-get update sudo apt-get install postfix heirloom-mailx
postfix, it'll ask you how to you want to setup it up. On the first screen, select
local only and proceed with the defaults for everything else.
Now, using your favorite editor, edit
/etc/aliases. It'll look something like this in the beginning:
# See man 5 aliases for format postmaster: root
What this means is that any mail sent to
postnaster will now be sent to
root as well. In this case, we want any mail sent to
root (for the cron mails and any other system mail) to be sent to
/etc/aliases to look like:
# See man 5 aliases for format postmaster: root root: norman
norman with your username obviously. Unless you have the same name/username as me. :) )
After that's all said and done, run the following command to
push the changes:
Now, after that run:
sudo dpkg-reconfigure postfix
You'll get the same screen you had before when installing
postfix. Run through the defaults (
Local Only, etc..). When you get to the part when it asks for the root and postmaster alias, just make sure it's the same as the one you added to
/etc/aliases above. Then, continue running through the defaults.
When you're done, run the following command to restart
postfix and get underway!
sudo service postfix restart
Now, if cron has an error, it'll be mailed to you. But, you're probably wondering, how in the world do I check my (local) mail?
To do that, run the command:
That simple. If there's no mail it'll say
No mail for <username>. Otherwise you'll get a neat terminal interface to use. See the man page for information on how to interact with your inbox.
Or, if you prefer, you can access your local man page by using:
And now, you're done! :)
P.S. You should read this to learn more about the
It is in
/var/log/syslog by default.
But it can be set up to create a separate cron.log, which is more useful.
This Q&A describes the process:
Also in this answer is the instructions to create a
wcron command that displays it is near-real-time. Plus, it links to another answer,
that shows how to change the log level to include more than just the start of jobs - level 15 will show errors and end time, also.