Go--Custom crontab log file location

Source: Internet
Author: User
Tags rsync

The original site is as follows:

Http://blog.itechol.com/space-33-do-blog-id-4945.html

customizing crontab log file Locations

Crontab is the most common scheduled task service under Linux. This article to share with you about Linux crontab log storage experience, I hope this article can teach you more things.

By default, the logs executed in Crontab are written under/var/log (described in CentOS for example), such as:

#ls/var/log/cron*
/var/log/cron/var/log/cron.1/var/log/cron.2/var/log/cron.3/var/log/cron.4

If the log has problems, you can refer to the following practices:

add log for crontab

The crontab log is simpler and sends a message to the user when a crond fails to perform a task. There are some problems that happen to be found on several of our web servers:

Simple Environment Description:

The company has WEB1 WEB2 WEB3 three application servers, of which the three servers through rsync to achieve real-time data synchronization; WEB1 for rsync clients, WEB2 WEB3 for rsync services, Custom rsync synchronization scripts on WEB1 synchronize data to WEB2 WEB3 through cron tasks. Cron tasks were found to work correctly during use, but synchronization data did not succeed; Use manual method Everything is OK, why.

Viewing the log found the following display:

June 10:47:01 Webmaster crond[3193]: (Root) CMD (/root/shell/rsync.sh)

And Crond also failed to send an email.

How to see if the cron task is actually executing.

This makes it easier to see why, given the fact that you are adding your own logs to the tasks in crontab.

so I did the following:

CRONTAB-E//Edit cron task, following cron task content

# rsync Aplication from/www

*/1 * * * */root/shell/rsync.sh >>/root/shell/for_crontab/mycron.log 2>&1

Red section for added content

The error output and standard output are exported to the Mycron.log.

By looking at the Mycron.log, you can clearly know if the cron task is performing correctly ...

Here's what's displayed in my Mycron.log file

[Root@webmaster for_crontab]# head-n Mycron.log

rsync:failed to open exclude file rules.txt:No such file or directory (2)

rsync error:error in file IO (code one) at EXCLUDE.C (1000) [client=2.6.8]

It can be seen in my rsync script using exclude to exclude files in error ...

Attachment: rsync Script Content

#!/bin/sh

# rsync Aplication from/www

/USR/BIN/RSYNC-VZRTOPG--progress--delete--exclude-from=/root/shell/rules.txt--password-file=/etc/rsync/ rsyncd.scrt/www/* webmaster@192.168.1.122::www

/USR/BIN/RSYNC-VZRTOPG--progress--delete--exclude-from=/root/shell/rules.txt--password-file=/etc/rsync/ rsyncd.scrt/www/* webmaster@192.168.1.123::www

~

The Red Identification section is the source of the error, because the exclude file is not previously indicated as an absolute path, causing the cron task to find no excluded file, so the script file cannot be executed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.