Viewing crontab log of timed tasks in Linux

In UNIX and UNIX like operating systems, the crontab command is often used to set the instructions to be executed periodically, which can also be understood as setting the timing task.

Sometimes the timing task in crontab is not executed successfully. What’s the reason?At this time, we need to go to the log to analyze it. How to view the log records of crontab?

1. linux

Look at/var/log/ cron.log This file can be viewed with tail – F/var/log/cron

2. unix

In the/var/spool/cron/tmp file, there are croutxxx001864 TMP files. You can see the tasks being executed from these files.

3. Mail task

In the/var/spool/mail/root file, there is a record of crontab execution log. Use tail – F/var/spool/mail/root to view the latest crontab execution.

A friend asked about whether the crontab of Linux has been executed or not. He has also written some shell scripts for basic backup. Combined with his own actual production environment, he briefly describes how to analyze whether the crontab is executed correctly through the cron execution log.

For example, Oracle users under the server have the following scheduled tasks

[oracle@localhost6 ~]$ crontab -l
00 1 * * 0 /home/oracle/backup/hollyipcc.sh
00 1 1 * * /home/oracle/backup/hollyreport_hollycrm.sh

The planned tasks of the system will be in/var/log first

[root@localhost ~]# cd /var/log/
[root@localhost log]# less cron
Sep 22 04:22:01 localhost crond[32556]: (root) CMD (run-parts /etc/cron.weekly)
Sep 22 04:22:01 localhost anacron[32560]: Updated timestamp for job `cron.weekly' to 2013-09-22
Sep 22 05:01:01 localhost crond[22768]: (root) CMD (run-parts /etc/cron.hourly)
Sep 22 06:01:01 localhost crond[25522]: (root) CMD (run-parts /etc/cron.hourly)
Sep 22 07:01:01 localhost crond[28255]: (root) CMD (run-parts /etc/cron.hourly)
Sep 22 08:01:01 localhost crond[30982]: (root) CMD (run-parts /etc/cron.hourly)

The above/var/log/cron will only record whether some planned scripts have been executed, but Linux will send email to the user every time to check whether the specific execution is correct and some information in the process of script execution.

As mentioned above, Linux will send an email to/var/spool/mail

[root@localhost6 log]# cd /var/spool/mail/
[root@localhost6 mail]# less oracle
Date: Sun, 25 Aug 2013 01:00:01 +0800
Message-Id: <[email protected]>
From: [email protected] (Cron Daemon)
To: [email protected]
Subject: Cron /home/oracle/backup/hollyipcc.sh
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:
X-Cron-Env:

backup hollyipcc

Export: Release 10.2.0.4.0 - Production on Sunday, 25 August, 2013 1:00:02

Copyright (c) 2003, 2007, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/******** dumpfile=hollyipcc_20130825.dmp logfile=hollyipcc_20130825.log directory
=back schemas=hollyipcc parfile=/home/oracle/backup/parfile.par
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 5.932 GB
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "HOLLYIPCC"."BASE_CONTACTSTATE_BAK":"P201203" 1.389 GB 15716014 rows

At this point, we can well judge whether the crontab script is executed, whether it is correct in the process of execution, and some error information. I hope this can help some friends understand the principle of crontab and diagnose the problems of crontab.

 

 

Read More: