Linuxcron service usage

Source: Internet
Author: User
The Cron service provides the following APIs: 1. directly use the crontab command to edit the following example to illustrate the problem: every morning *** echo & quot; Goodmorning. & quot; & gt;/tmp/test.txt // pay attention to echo alone, and no output is visible from the screen, because...
The Cron service provides the following APIs: 1. directly use the crontab command to edit the following example to illustrate the problem: every morning, *** echo "Good morning. ">/tmp/test.txt // note that no output is visible from the screen with pure echo, because cron has emailed any output to the root mailbox. 0 */2 *** echo "Have a break now every two hours. ">/tmp/test.txt every two hours from PM to AM, 8 *** echo "Have a good dream :)">/tmp/test.txt AM, AM, Am- 3 command line a.m. on April 9, January 1 4 1 1 * command line cron service provides the crontab command to set the cron service, the following are some parameters and descriptions of this command: crontab-u // sets a user's cron service, generally, when executing this command, the root user needs this parameter crontab-l // to list the details of a user's cron service. crontab-r // delete the cron service crontab-e of no user. // edit a user For example, the root user's cron service can view his cron settings: crontab-u root-l. For example, the root user wants to delete fred's cron settings: crontab-u fred-r www.2cto.com when editing the cron service, the edited content has some formats and conventions. enter: crontab-u root-e to enter the vi editing mode, the edited content must conform to the following format: */1 ***** ls>/tmp/ls.txt. The first part of the format is the time setting, the subsequent part is the command to be executed. if there are too many commands to be executed, you can write these commands into a script and then directly call this script here, when calling the command, remember to write out the command> the whole path. 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? R (0-23) Date (1-31) month (1-12) Week (0-6) // 0 indicates Sunday. in addition to numbers, there are also several special symbols: "*", "/", "-", and ". * indicates the number in all values, "/" indicates the meaning of each, "*/5" indicates every five units, "-" indicates the number from a number to a number, "," separate several discrete numbers. After you edit the cron settings of a user, cron automatically generates a file with the same name under/var/spool/cron. The cron information of this user is recorded in this file, this file cannot be edited directly. you can use crontab-e to edit it.>. 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. 2. edit the/etc/crontab file and configure the cron service to read not only all files in/var/spool/cron once per 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/bash PATH =/sbin:/bin:/usr/sbin:/usr/bin MAILTO = root // if an error occurs, or there is data output. The data is sent to the account HOME as an email = // path for the user to run, here is the root directory # run-parts www.2cto.com 01 ***** 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. m Onthly // Run/etc/cron every month. note the "run-parts" parameter for the script in monthly. If this parameter is removed, you can write a script name to be run later, instead of the folder name. command: use at: at-V [-q queue] [-f file] [-mldbv] TIME example: Run/bin/ls at five o'clock P.M. after three days: at 5 pm + 3 days/bin/ls: Execute/bin/ls at five o'clock P.M. after three weeks: at 5 pm + 2 weeks/bin/ls execute at tomorrow/bin/date: at tomorrow/bin/date at the last minute of the last day of January 1, 1999 print the end of world! At 23:59 12/31/1999 echo the end of world! Detailed description: at allows users to run a program or command at a specific TIME. the TIME format is HH: MM, where HH is hour and MM is minute, you can even specify spoken words such as am, pm, midnight, noon, and teatime (four o'clock P.M. If you want to specify a time later than one day, you can use the MMDDYY or MM/DD/YY format. MM indicates the month, DD indicates the day, and YY indicates the year. In addition, users can even use now + time interval to elastically specify the time. the time interval can be minutes, hours, days, and weeks. In addition, you can also specify today or tomorrow to indicate today or tomorrow. After you specify the time and press enter, at enters the conversation mode and requires you to enter the command or program. after you enter the time, press ctrl + D to complete all the actions, the execution result will be sent back to your account. Parameter:-V: printed version number-q: The specified Queue is used for storage. the at data is stored in the so-called queue. you can use multiple queue at the same time, the number of queue is a, B, c... z and A, B ,... Z has 52-m in total: even if no result is output after the program/command execution is completed, you must send a mail to the user-f file: read the pre-written command file. The user does not have to use the conversation mode for input. you can first write all specified files to the file and then read them into-l: list all specified values (users can also directly use atq instead of at-l)-d: delete the specified value (users can also directly use atrm instead of at-d)-v: list all completed but not deleted specified authors wsj356428476

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.