Linux creates scheduled tasks for the current user

Source: Internet
Author: User


Linux creates a scheduled task for the current user. type crontab-e to edit the crontab service file www.2cto.com. For example, the file content is as follows: */2 *****/bin/sh/home/admin/jiaoben/buy/deleteFile. sh save the file and exit */2 ***/bin/sh/home/admin/jiaoben/buy/deleteFile. sh */2 **** you can use this field to set when to execute the script/bin/sh/home/admin/jiaoben/buy/deleteFile. THE sh field can be used to set the script to be executed. Note that bin/sh refers to the path in which the script is stored when the command for running the script is followed. check whether the crontab service under the user is successfully created. run crontab-l command 3. start the crontab service. Generally, start the service./sbin/ Service crond start if the root user's cron service can use sudo service crond start, it is important to note that the commands of the services started by linux systems of different versions are also different, for example, in my virtual machine, you only need to use sudo service cron restart. If you type service cron start directly at the root, the service www.2cto.com 4 can be started. check whether the service is running with ps-ax | grep cron 5. the crontab command cron Service provides the crontab command to set the cron service. The following are some parameters and descriptions of this command: crontab-u // set the cron service of a user, 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's cron service, such as root, views his cron settings: crontab-u root-l. For example, root wants to delete fred's cron settings: crontab-u fred-r 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> the crond resident command scheduled by/tmp/ls.txt is the command used by linux to regularly execute programs. After the operating system is installed, the Job Scheduling command www.2cto.com is started by default. Each worker of the crond command regularly checks whether there is any job to be executed. If there is a job to be executed, the job is automatically executed. 6. crontab command option:-u specifies a user-l to list a user's task plan-r to delete a user's task-e to edit a user's task 7. cron File Syntax: hour, day, month, week, command 0-59 0-23 1-31 1-12 0-6 (value range, 0 indicates that a task is usually displayed in a row on Sunday) remember the meanings of several special symbols: "*" indicates a number in the value range, "/" indicates "every", and "-" indicates a number to a number. ", "Separate several discrete numbers 8. you can run the crontab-e command to edit the syntax of the task scheduling setting file. The cron file of the corresponding user in/var/spool/cron is edited, you can also directly modify the format of the/etc/crontab file as follows: Minute Hour Day Month Dayofweek command Minute Hour Day Month Day weekly command each field represents the meaning of the following: minute executes the task in minutes of each hour. Hour executes this task on the nth Day of every Month on the nth Day of every Day on the nth Day of every Month on the nth Day of every year on the job DayOfWeek run this task Command specifies the program to be executed in these fields, except that "Command" is a field that must be specified each time, other fields are optional fields, which can be determined as needed. For unspecified fields, use "*" to fill their positions. Example: * ls indicates that the ls command is executed once every 5th minutes of every hour. * 5 * ls indicates that the ls command is executed at every day. * 7 8 * ls indicates the 8 th day of every month. execute the ls command at AM 30 5 8 6 * ls to specify to execute the ls command at AM on April 9, June 8*0 ls to specify to execute the ls command at AM on every Sunday. [Note: 0 indicates Sunday, 1 indicates Monday, and so on. sun indicates Sunday, mon indicates Monday, and so on.] 30, 20 ** ls: Execute the ls command at on the 10th and 20th of every month [Note: ", [Note: "-" is used to connect to consecutive periods] */15 ***** ls executes the ls command every 15 minutes [that is, the ls command is executed every hour for 0th 15 30 45 60 minutes] 30 6 */10 ** ls every month, run the ls command at every 10 days [that is, run the ls command at on the 1st, 11th, 21st, and 31st of every month.] Run/etc/cron at every day as root. all executable files in the daily directory are 50 7 * root run-parts/etc/cron. daily [Note: run-parts parameter indicates that all executable files in the following directory are executed.] 9. There are two ways to add a new scheduling task: 1) Enter crontab-e in the command line and add the corresponding task. The wq disk is saved and exited. 2) directly edit the/etc/crontab file, that is, vi/etc/crontab, and add the corresponding task. 10. view scheduling task crontab-l // list all current scheduling tasks crontab-l-u jp // list all scheduling tasks of user jp 11. delete the task scheduling job crontab-r // delete all task scheduling jobs 12. example 1: Execute the ls command at every day, output the result to the/jp/test file for 30 5 * ls>/jp/test 2> & 1 Note: 2> & 1 indicates the execution result and error message. 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 www.2cto.com # run-parts 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. 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. For example: 1) enter crontab-e in the command line and add the corresponding task. Then, the wq disk exits. 2) directly edit the/etc/crontab file, that is, vi/etc/crontab, and add the corresponding task 11 2 21 10 * rm-rf/mnt/fb

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.