Linux Curl timed Task __linux

Source: Internet
Author: User
Tags curl file permissions

1. Linux timing tasks are set in the/etc/crontab file, using commands to view

[python] view plain copy Cat/etc/crontab

In the/etc directory there is a crontab file, where there are some scheduling programs running on the system. Each user can establish their own scheduling crontab.


2. User settings for Scheduled tasks in/etc/cron.deny and/etc/cron.allow files

/etc/cron.deny indicates that users who cannot use the crontab command/etc/cron.allow represent users who can use crontab. If two files exist at the same time, then/etc/cron.allow first. If two files do not exist, only a superuser can schedule the job.

There are no settings for this machine, so the results are printed as shown above.


Each user will generate a crontab file of their own. These files are in the/var/spool/cron directory:

The timing task of this machine is root, and the contents of the root are printed as follows:


Here's how some shell commands are meant to be interpreted:

[python] view plain copy 0 0 * * * find/opt/app/log/-type f-mtime +30-exec rm {} \; It's 0:0 every day. Find the/opt/app/log/file all the files below 30 days, and then delete them.

Related key knowledge points: Find command:

Find Pathname-options [-print-exec-ok]
The Find command has many options or expressions, with each option preceded by a horizontal bar-. Let's take a look at the main options for the command, and then give some examples.

-name finds files by file name.
-perm to find files by file permissions.
-prune Use this option to make the f i n command not look in the currently specified directory, and if the-depth option is used, the-prune option is ignored by the Find command.
-user to find files according to the owner of the file.
-group finds files by the group to which the file belongs.
-mtime-n or +n locates files according to the time the file was changed,-n indicates that the file change time is now within n days, and +n indicates that the file change time is now N days ago. The Find command also has the-atime and-ctime options, but they are all similar to the-mtime option, so we'll just introduce the-mtime option here.
-nogroup finds a file that does not have a valid owning group, that is, the group that the file belongs to does not exist in/etc/groups.
-nouser finds a file that has no valid owner, that is, the owner of the file does not exist in/etc/password.
-newer file1! File2 find change times than file File1 new but older files than file file2.
-type find a type of file, such as:
B-block device files.
D-Directory.
C-Character device files.
P-pipe file.
L-Symbolic link file.
F-Normal files.
-size N[c] finds files with a file length of n blocks, with C indicating the length of the file in bytes.
-depth when looking for a file, first look for the files in the current directory and then look in their subdirectories.
-fstype finds files in a type of file system that can usually be found in the configuration file/etc/fstab, which contains information about the file system in this system.
-mount does not cross the file system mount point when locating files.
-follow if the find command encounters a symbolic link file, it tracks to the file that the link points to.
-cpio Use the Cpio command on matching files to back up these files to a tape device.


EXEC command:
The command command is followed by the-exec parameter, with the following attention points:
The termination of the command order, using '; ' (semicolon) to determine that there must be a '; ' at the back.
' {} ', using {} to represent the filename, that is, the file filtered in the previous process, used for command processing
In particular, for different systems, the direct use of semicolons may have different meanings, using the escape character ' \ ' in front of the semicolon clearly, for the problems we have encountered, the main reason is this cause.

3.cron Syntax:

Cron file Syntax:

Hour and Moon Week command

0-59 0-23 1-31 1-12 0-6 Command (value range, 0 for Sunday One for a row corresponding to a task)

Remember the meaning of several special symbols:

"*" represents the number in the range of values,
"/" stands for "every",
"-" represents from a number to a number,
"," separate several discrete numbers 4. The writing of task scheduling settings file
can be edited using the Crontab-e command, edited by the/var/spool/cron of the corresponding user's cron file, or directly modify the/etc/crontab file
The specific format is as follows:
Minute Hour Day Month dayofweek command
Minutes hours days month days per week order
Each field represents the following meanings:
Minute the first few minutes of each hour
Hour a few hours a day to perform this task
Day of the month to perform this task
Month a few months of the year to perform this task
DayOfWeek to perform the task on the first day of the week
Command Specifies the program to be executed
In these fields, except for "Command", which must be specified each time, the other fields are optional

fields, depending on the need to decide. For fields that are not specified, use "*" to fill their position.
Examples are as follows:
5 * * * * ls Specifies the first 5 minutes of every hour to execute the LS command
5 * * * ls specifies 5:30 daily execution of LS command
7 8 * ls specifies 7:30 points per month 8th to execute LS command
5 8 6 * ls specifies every June 8 5:30 execution of the LS command
6 * * 0 ls Specifies 6:30 execution of the LS command per Sunday [Note: 0 means Sunday, 1 means Week 1,

By analogy, it can also be expressed in English, Sun said Sunday, Mon said Monday. ]

3 10,20 * * ls 10th and 20th 3:30 Execute ls command [note: "," used to connect multiple discontinuous periods]

8-11 * * * ls 25 minutes per day at 8-11 o ' hour to execute the LS command [note: "-" to connect consecutive periods]

*/15 * * * * ls is executed once every 15 minutes by the LS command [that is, the No. 0 15 30 45 60 minutes per hour executes the LS command]

6 */10 * ls is executed once every 10 days, the LS command [that is 1, 11, 21, 31st of the month is 6:30 executes the LS command. ]

Executes every executable file in the/etc/cron.daily directory as root 7:50 daily

7 * * * Root run-parts/etc/cron.daily [Note: run-parts parameter indicates that all executables in the following directory are executed. ]

5. New Scheduling tasks

There are two ways to add new scheduling tasks:
1, at the command line input: Crontab-e then add the corresponding task, Wq save the disk exit.
2, directly edit/etc/crontab file, that is, vi/etc/crontab, add the corresponding task.

3 Add the relevant Shell dispatch command to the corresponding user file in the/var/spool/cron directory:


6. View Scheduled Tasks
Crontab-l//List all current Scheduled tasks
Crontab-l-u JP//List all scheduling tasks for user JP

*/1 * * * */usr/bin/curl http://172.16.0.106/index.php/Home/Index/crons Access this URL once per minute

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.