Linux Mint: How to Check Cron Logs (crontab -e)
In this post you can find information how to deal with problems related to CRON jobs:
- how to find logs
- identify errors
- (CRON) info (No MTA installed, discarding output)
If you need more info about CRON scheduler:
- Start and stop application from terminal in Linux Mint 19 / Ubuntu 18.04 - example for beginners
- Job automation in Linux Mint for beginners 2019 - advanced examples
Step #1: Where is the CRON log in Linux Mint
By default the logs in Ubuntu and Linux Mint from CRON execution can be found in: /var/log/syslog
. In this log file there are many different log messages so best way to extract CRON related messages is by:
grep CRON /var/log/syslog
output:
Mar 15 09:00:01 vanx-machine CRON[7205]: (root) CMD (timeshift --check --scripted)
Mar 15 09:12:01 vanx-machine CRON[8128]: (vanx) CMD (/home/vanx/cron/seoanalyzer.sh)
Mar 15 09:17:01 vanx-machine CRON[8638]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Mar 15 09:30:01 vanx-machine CRON[9508]: (vanx) CMD (DISPLAY=:0 /home/vanx/cron/weekly.sh)
Mar 15 09:32:29 vanx-machine CRON[9507]: (CRON) info (No MTA installed, discarding output)
This command will output all recent executions. If the result is empty most probably nothing was scheduled. Then you can check by:
crontab -e
Step #2: Reading the logs
Successful execution is logged as:
Mar 15 09:12:01 vanx-machine CRON[8128]: (vanx) CMD (/home/user/cron/seoanalyzer.sh)
You can find next information:
- execution date -
15th of March
- execution time -
09:12:01
- machine -
vanx-machine
- user -
vanx
- command -
/home/user/cron/seoanalyzer.sh
In case of errors you will see something like(unless you have MTA installed):
Mar 15 09:32:29 vanx-machine CRON[9507]: (CRON) info (No MTA installed, discarding output)
This error will be covered in next section.
Step #3: (CRON) info (No MTA installed, discarding output)
From the output above we notice this message:
(CRON) info (No MTA installed, discarding output)
The message indicates two things:
- the last job execution failed for some reason
- MTA (Mail Transfer Agent) is not installed (which is the case for Linux Mint and Ubuntu)
The solution of No MTA installed, discarding output
is:
- installation of
postfix
- as local setup - by using next commands:
sudo aptitude install postfix
- Choose Local during setup
- Select name - i.e. - your user name
- Access the logs(you will need to rerun the failing job):
sudo tail -f /var/mail/vanx
By last command you can find detailed information about the errors and output of the CRON scripts if any.
Example:
File "/home/vanx/Software/Tensorflow/environments/venv36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 966, in find_element
'value': value})['value']
File "/home/vanx/Software/Tensorflow/environments/venv36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "/home/vanx/Software/Tensorflow/environments/venv36/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"galaxyIframe"}
Step #4: Redirect CRON job output(no installation of MTA)
If you:
- can't install MTA
- don't like the idea of MTA
- installation of additional software on your machine
- or want to analyse single CRON job
then you can redirect the output of your CRON job by command next steps:
- Edit the CRON schedule file
crontab -e
- Find the command for which you like to redirect output:
0 3 * * * /cmd/to/run.sh
- Redirect the output by this command
0 3 * * * /cmd/to/run.sh >> /var/log/cmd_to_run_log_file.log
- Run the command again and check what happened by:
sudo tail -f -n 50 /var/log/cmd_to_run_log_file.log
Where command tail will product 50 last lines in the given file.
Note 1: Use use if the issues are related to root CRON - sudo crontab -e
Note 2: You can redirect output by 0 3 * * * cmd >> /var/log/cmd_to_run_log_file.log 2>&1