Linux timed Tasks

Source: Internet
Author: User
Tags rsyslog

Accustomed to the use of windows  using  linux   crontab  Manage timed tasks is not suitable

So the basic usage is summarized as follows.

Create a simple scheduled task

Output the current time per minute and output to the Time.log file in the user's home directory.

$ crontab-e* * * * * echo ' date ' >>/home/xxx/time.log

The path to the Crontab program is/usr/bin/crontab.

The scheduled tasks for each user can be queried in the/var/spool/cron/crontabs/directory.

Root permission is required to enter this directory. The user's scheduled tasks are recorded in each file named after the user name.

Note that you do not use VI to edit these files directly.

Every job that cron runs is recorded in the/var/log/cron log file, but Ubuntu turns off the log of cron by default.

Open as: Open the configuration file for the Rsyslog service

$ sudo vim/etc/rsyslog.d/50-default.conf

Remove the previous comment from the following line

Cron.*/var/log/cron.log

Restart Rsyslog

$ sudo service rsyslog restart

Now that you can see the/var/log/cron file, viewing the file is an important way to resolve the timing task error.

Controlling user Run timed tasks

If you do not want a user to run a timed task, write his account directly to the /etc/cron.deny file. Note that an account is one line.

course you can also use  /etc/cron.allow  file to explicitly specify the account number of the user who can run the scheduled task, and  /etc/cron.allow   than  /etc/cron.deny  high priority.

But it feels a little messy, so it's better to just use one of them.

crontab Command

-U: Only Root has permission to perform this task, that is, to help other users create/remove crontab Scheduled Tasks

-E: Edit the contents of the Crontab

-L: Show crontab content

-r: Remove all crontab content, and if you want to remove only one item, use the-e edit

Time Format

Minute hour date Month Week command

Digital range 0-59 0-23 1-31 1-12 0-7 echo "Hello" >> abc.log

Meaning of special characters

* (asterisk) on behalf of any time accepted.

, (comma) represents the meaning of the separation period.

-(minus sign) represents a period of time in the range.

/n (slash) that n represents a number, spaced every n units.

CASE1: Executed once every May 1 10:5

5 1 5 * command

Case2: Three points per day, six points for each execution

0 3,6 * * Command #注意这里使用了逗号

CASE3: Every 8:20, 9:20,10:20,11:20 executes once.

8-11 * * * Command #注意这里使用了减号

CASE4: executed every five minutes

*/5 * * * * Command #注意这里使用了/n

CASE5: Executed at 10 points per week

* Ten * * 1 command
Configure system-level scheduled Tasks

CRONTAB-E is used to set user-level scheduled tasks. What if you want to set the system-level timing tasks?

The answer is to edit the configuration file for the system-level scheduled task directly using root permissions: /etc/crontab.

For example , open the editor directly with vim:

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/952033/201609/952033-20160911160543137-1498575083. PNG "width=" 856 "height=" 206 "style=" margin:0px;padding:0px;border:0px; "/>


Linux timed Tasks

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.