In Centos, crontab specifies the execution user

Source: Internet
Author: User
In Centos, you can configure crontab to regularly execute tasks. the execution body can be a system command or a script written by yourself. you can also assign users to execute tasks. You can configure crontab in two ways. Method 1: Use the crontab command. for example, add a new or edit existing one. use crontab-e to enter the configuration file. At this time, the performer of crontab configuration is the current login user. if the current user is root, you need to configure it for other users, you can use crontab-e-u User

In Centos, you can configure crontab to regularly execute tasks. the execution body can be a system command or a script written by yourself. you can also assign users to execute tasks. You can configure crontab in two ways.
Method 1: Use the crontab command, for example, to add a new or edit an existing one, use:

crontab -e

You can access the configuration file. At this time, the performer of crontab configuration is the current login user. if the current user is root, you need to configure it for other users, you can use

Crontab-e-u user name or su user name crontab-e

One disadvantage of this method is that the crontab configured in the current system is not in a configuration file, which makes it inconvenient for the administrator to query the number of crontabs.

Method 2: directly add it to the/etc/crontab file, but the root identity is required. Open the file and you will see information similar to the following:

SHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=rootHOME=/# For details see man 4 crontabs# Example of job definition:# .---------------- minute (0 - 59)# |  .------------- hour (0 - 23)# |  |  .---------- day of month (1 - 31)# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# |  |  |  |  |# *  *  *  *  * user-name command to be executed

To add a new crontab, you only need to add it at the end of the file.Note that the user name must be specified here, while Method 1 does not.If it is specified, it is considered as part of the command, which may lead to crontab execution failure.

If the server is managed by the root user, we recommend that you add crontab to use method 2. in this way, all the scheduled tasks in the system are together and you can see at a glance.


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.