How to use a scheduled task in combination of wget and crontab ......

Source: Internet
Author: User

How to use a scheduled task in combination of wget and crontab ......

After even tests and practices, this is definitely a good article! Believe me ...... Author: PHPMA Lujiang Youyu ......

Execute crontab-e to edit the task file and add a line in the following format

Minute hour day month week command

For example
0 4 * wget -- spider http://www.google.com
It means running wget at 04:00 every day ......

The following is a good introduction to crontab:

Crontab task format

* *** Task
Task by hour, day, month, and week

1st columns minute 1 ~ 5 9 (0 indicates 0 points)
2nd columns hour 1 ~ 2 3 (0 indicates midnight)
3rd columns daily 1 ~ 3 1
4th columns Month 1 ~ 1 2
5th columns in a week 0 ~ 6 (0 indicates Sunday)
6th columns of commands to run

Some examples:
30 21 ***/apps/bin/cleanup. Sh
The example above indicates that C l e a n u p. s h in the/a p s/B I n directory of 2 1: 3 0 every night.
45 4, 10, 22 **/apps/bin/backup. Sh
The example above indicates the 4: 4 5 running/a p s/B I n directory B A C K u p on the 1, 1, 0, and 2 every month. s h.
10 1 ** 6, 0/bin/find-name "core"-exec RM {}/;
The preceding example indicates that an f I n d command is run at every Saturday and Sunday.
0, 30 18-23 ***/apps/bin/dbcheck. Sh
The preceding 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 11: 0 0 p m runs/a p s/B I n directory Q T r e n d. s h

Two ways to implement scheduled tasks
One is to edit a file and load it with crontab
One is to use crontab-E for direct editing.

My own example

Break into a pile of characters into a file every minute
First VI crontab1
# Every minute echo Char to file
1-59 **** echo 'date' "LJ/N">/opt/Lijie/lj.txt
It is best to add comments
In this way, the purpose of the current scheduled task can be clearly defined.
Then crontab crontab1 loads the scheduled task crontab1.

 

The other is
Crontab-e
# Every minute echo Char to file
1-59 **** echo 'date' "LJ/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", rather than the execution result of the date command.

>>Is appended to the end of the file, and> is directly overwriting the file

If crontab-e cannot be edited
So your environment variables are not configured.
Enter VI/etc/profile
Add
Editor = vi
Export Editor

Crontab-l list all scheduled tasks

To delete a scheduled task
So
Crontab-e
Comment out the corresponding scheduled task statement
For example, to delete the scheduled task that I just defined
# Every minute echo Char to file
1-59 **** echo 'date' "LJ/N">/opt/Lijie/lj.txt
Only
# Every minute echo Char to file
#1-59 **** echo 'date' "LJ/N">/opt/Lijie/lj.txt

If crontab-R is used

Delete all scheduled tasks.

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.
Do not use the crontab file.

2. The crontab log file is/var/log/cron.

3. If you use crontab <FILENAME> to set Cron, pay attention to file garbled characters. 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.

Good things, share ...... Author: Lujiang Youyu PHPMA

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.