Linux timed Tasks

Source: Internet
Author: User

Accustomed to scheduling tasks using Windows, it is not appropriate to use crontab in Linux to manage timed Tasks .

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.

'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.

Of course you can also use the /etc/cron.allow file to explicitly specify the account of the user who can run the scheduled task, and the /etc/cron.allow is higher than the/etc/cron.deny 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

Command

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

Command # Note The comma is used here

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

Command # Note that a minus sign is used here

CASE4: executed every five minutes

Command # Note that the/n is used here

CASE5: Executed at 10 points per week

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:

Linux Scheduled Tasks

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.