Debian scheduled task management cron settings

Source: Internet
Author: User

Debian scheduled task management cron settings (the easiest way to shut down at a specific time every day: 1. gedit/etc/crontab 2. add a line at the end of the file: 01 22 **** root halt-p # indicates shutdown at every day.) All tasks with the system administrator privilege must be in/etc, because they are all configuration files. If you have scheduled tasks that require daily (daily), weekly (weekly), or monthly (monthly) running as administrators, place them in/etc/cron. {daily, weekly, monthly. They will be activated from/etc/crontab and run in alphabetical order of file names. Www.2cto.com on the other hand, if you have a scheduled task that needs to run as a specific user or at a specific time or in a specific cycle, you can use/etc/crontab, or/etc/cron. d/whatever, and the latter will be better. These special files can contain an additional domain that allows you to specify the user account that runs the scheduled task. In any case, you only need to edit these files and cron will automatically process them. There is no need to run a special command. There are two ways to run a command or Script: crontab: execute a task once or multiple times. at: only once. crontab is used to read a crontab file. It is a common text file that lists the command parameters and options of the task to be executed in each line, and the time when the task is to be executed. (The cron software runs in the background and often checks the/etc/crontab file. The cron software also checks the/var/cron/tabs directory and searches for the new crontab file. These crontab files store information about cron tasks executed at specific times .) All users at www.2cto.com can set their own crontab files. However, root can use two files to control access:/etc/cron. allow: if this file exists, crontab can be used only for users listed in it. /etc/cron. deny: if this file exists, users listed in this file cannot use crontab. all crontab files are saved in the/var/spool/cron/crontabs/directory. However, because normal users cannot read or write this directory, they must use the crontab command to join the scheduled task. Many system administrators use three files to schedule the task:/etc/cron. daily,/etc/cron. weekly, and/etc/cron. monthly. as prompted by their names, these directories contain scheduled tasks with rules, on a daily basis, run the "How to Use crontab file" once every week or every month, type crontab options user or crontab-e (only root can specify the crontab file of other users) crontab command (scheduling) ========================================================== =====================================1. directly use the crontab command to edit the crontab command provided by www.2cto.com cron to set the cron service. Parameters and Description: crontab-u // sets a user's cron service, generally, root users need this parameter when executing this command. crontab-l // list the details of a user's cron service. crontab-r // Delete the cron service crontab-e/of each user/ /edit a user's cron service, such as root, to view their cron settings: crontab-u root-l again, for example, root wants to delete the cron setting of fred: crontab-u fred-r when editing the cron service, the edited content has some formats and conventions. input: crontab-u root-e enters the vi editing mode. The edited content must conform to the following format: */1 ***** ls> the first part of the format of/tmp/ls.txt is the time setting, and the other part is the command to be executed. If too many commands are to be executed, you can write these commands into a script, and then directly call this script here. Remember to write the complete path of the command. We have a certain agreement on the time setting. The first five * numbers represent five numbers. The value range and meaning of the numbers are as follows: minute (0-59) is small? (0-23) Date (1-31) month (1-12) Week (0-6) // 0 indicates that there are several special symbols in addition to numbers on Sunday */-, * Indicates the number in all value ranges/indicates the meaning of each */5 indicates each 5 units-indicates that from a number to a number, separate several discrete numbers. The following example illustrates the problem: Every morning, *** echo "Good morning. ">/tmp/test.txt // pay attention to pure echo, and no output can be seen from the screen, because cron emailed any output to the root mailbox every two hours 0 */2 *** echo "Have a break now. ">/tmp/test.txt every two hours from PM to am, 8 *** echo "Have a good dream :)">/tmp/test.txt, the 4th of each month and the Monday of every week By a.m. on Wednesday, a.m., A.M, cron automatically generates a file with the same name as/var/spool/cron. The cron information of this user is recorded in this file and cannot be edited directly, you can only use crontab-e for editing. The cron reads the file every minute after it is started, and checks whether to execute the commands in it. Therefore, you do not need to restart the cron service after the file is modified. Edit the/etc/crontab file at www.2cto.com and configure the cron service to read not only all files in/var/spool/cron every minute, but also/etc/crontab once, therefore, we can use the cron service to configure this file. Crontab configuration is intended for a user, and editing/etc/crontab is a system task. The file format of this file is: SHELL =/bin/bashPATH =/sbin:/bin:/usr/sbin:/usr/binMAILTO = root // if an error occurs, or there is data output, the data is sent to the account HOME as a mail = // user running path, here is the root directory # run-parts01 *** root run-parts/etc/cron. hourly // run/etc/cron hourly. hourly script 02 4 *** root run-parts/etc/cron. daily // run/etc/cron every day. daily script 22 4 ** 0 root run-parts/etc/cron. weekly // run/etc/cron every week. weekly script 42 4 1 ** root run-parts/etc/cron. monthly // run/etc/cron every month. for the script in monthly, pay attention to the "run-parts" parameter. If this parameter is removed, you can write a script name to be run later, instead of the folder name.

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.