How to combine a scheduled task with a crontab

Source: Internet
Author: User

Wget and crontab combination scheduled task usage such as 0 4 *** wget -- spider http://www.google.com means to run wget at 04:00 every day ...... The following is a good introduction to crontab in the previous article: crontab task format ***** task minute-by-day, month, week, task, column 1st, minute 1 ~ 5 9 (0 indicates 0 points) 2nd columns hour 1 ~ 2 3 (0 indicates midnight) 3rd columns Day 1 ~ 3 1 4th columns Month 1 ~ 1 2 5th columns day of week 0 ~ 6 (0 indicates Sunday) Example of the command to be run in column 6th: 30 21 ***/apps/bin/cleanup. sh the above example indicates that c l e a n u p in the/a p s/B I n directory of 2 1: 3 0 every night. s h. 45 4, 10, 22 **/apps/bin/backup. sh the example above indicates that the 4: 4 5 run/a p s/B I n directory B a c k u p on the first, 1, 0, and 2 every month. s h. 10 1 ** 6, 0/bin/find-name "core"-exec rm {}/; the above example indicates 1 of every Saturday and Sunday: 1 0 run an f I n d command. 0, 30 18-23 ***/apps/bin/dbcheck. sh the above example indicates that every day 1 8: 0 0 to 2 3: run between 0 and every 3 0 minutes/a p s/B I n Directory d B c h e c k. s h. 0 23 ** 6/apps/bin/qtrend. sh the above example indicates that every Saturday's 11: 0 0 p m run/a p s/B I n directory q t r e n d. s h implements scheduled tasks in two ways: editing a file, loading with crontab one is to use crontab-e direct edit take effect I own an example every minute to a file into a bunch of characters First vi crontab1 # every minute echo char to file1-59 *** * echo 'date' "lj/n">/opt/lijie/lj.txt it is best to add comments to clarify the purpose of the current scheduled task and then load crontab crontab1 to the scheduled task crontab1. another type is crontab-e # every minute echo char to file1-59 *** echo 'date' "l J/n ">/opt/lijie/lj.txt date is enclosed in single quotes, indicating that if date is a command, it will be executed as a command. If you use date directly, the output is the string "date" instead of the execution result of the date command> appended to the end of the file,> directly overwrite the file. If crontab-e cannot be edited, the environment variable is not configured. Please go to vi/etc/profile and add EDITOR = viexport EDITORcrontab-l to list all scheduled tasks. to delete a scheduled task, comment out the corresponding scheduled task statement crontab-e, for example, delete the scheduled task I just defined # every minute echo char to file 1-59 **** echo 'date' "lj/n">/opt/lijie/lj.txt only needs # every minute echo char to file #1-59 **** e Cho 'date' "lj/n">/opt/lijie/lj.txt delete all scheduled tasks with crontab-r. Note: 1, if you use the crontab file to load a scheduled task, the scheduled task will be washed out. Therefore, if you want to add a scheduled task, you 'd better use crontab-e to add a scheduled task instead of the crontab file. 2. The crontab log file is/var/log/cron3. If you use crontab <filename> to set cron, be sure to pay attention to the file garbled. I encountered a problem. The/var/log/cron log shows Dec 28 11:34:00 TARGET CROND [13449]: (hnuc) CMD (/home/hnuc/shell/t. sh ^ M ~ M is garbled because: I used the cron file edited by editplus, and the carriage return line break symbol in it is dos rather than linux or unix. Here ^ M is actually a dos line break, which is parsed in linux.

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.