Use crontab liunxu

Source: Internet
Author: User

Crontab liunxu's use of Crontab is a very convenient program for scheduled (Cyclic) Execution of a task on unix/linux systems to use the cron service and view the cron service status using the service crond status, if the task is not started, the service crond start starts it. The cron service is a scheduled service. You can use the crontab command to add or edit the task to be periodically executed: crontab-u // set 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 the cron service of a user, for example, view the cron settings of the root user: crontab-u root-l again, for example, root wants to delete fred's cron setting: 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 comply with the following formats: */1 ***** ls>/tmp/ls.txt edit the/etc/crontab file and add a line at the end: in this way, the system is configured to automatically restart at every morning. You need to set crond as a service automatically started after the system starts. d/rc. in local, add service crond start at the end. If you still need to load other services on the system, you can continue to add startup commands for other services. For example, basic usage of service mysqld start: 1. crontab-l list the current crontab Task 2. crontab-d: Delete the current crontab task. 3. crontab-e (crontab-r on solaris5.8) edits a crontab task and ctrl_D ends 4. crontab filename uses filename as the task list file of crontab and loads the crontab file. rows in the crontab file are composed of six fields. Different fields are separated by spaces or tab keys. The first five fields specify the time (0-59) hour (0-23) Date (1-31) month (1-12) for the command to run) the day of the week (0-6, where 0 represents Sunday) 6th fields are a string example to be executed at the appropriate time: # min hour day month dayofweek command # Every morning 06:10 10 6 * date #0 */2 * date every two hours (solaris 5.8 does not seem to support this method) # Every two hours from PM to am, am, 8 * ** date #4 of each month and 11: 0 11 a.m. from Monday to wed date of every week # a.m. of February 4: 0 4 1 jan * date supplement: when using crontab, note that the environment variables that can be accessed in the running script are not necessarily the same as those in the current test environment. The risk is to set the environment variable (export) in the running script program (1) first create a file crond.txt as follows, restart 36 5 *** reboot (2) at 05:36 every morning) upload to the/opt directory (3) run the command crontab/opt/crond.txt crontab-l to make the configuration file take effect: If the configuration file takes effect, you have to restart cron. Remember, since the cron configuration file under each user is modified. Restart the cron server. In Fedora and Redhat, we should use; [root @ localhost ~] #/Etc/init. d/crond restart if you want crond to run at startup, you should change its running level. [root @ localhost ~] # Chkconfig -- levels 35 crond on service crond status to view the cron service status. If the cron service is not started, service crond start starts it. The cron service is a scheduled service, you can use the crontab command to add or edit the rontab file of the task to be periodically executed. Each row contains six fields (minutes, hours, day of month, month, day of week, and command) separated by spaces or tabs, where: minutes: minute domain, value range: 0 to 59 hours: small time domain, the value range is 0 to 23 days of month: date. The value range is 1 to 31 month: month. The value range is 1 to 12 days of week: week, the value range is 0 to 6, and the Sunday value is 0 command: the command to be run. If a field is *, it indicates that the command can have all possible values in this field. In-circle execution. If a field is two numbers separated by a hyphen, the command can be executed within the range of two numbers (including the two numbers themselves ). If a field is composed of a series of values separated by commas, the command can be executed within the range of these values. If both the date and week fields have values, these two fields are valid. Write a file to start the automatic backup process. Cd/opt touch reboot.txt Add the following content to reboot.txt: 0 4 *** reboot crontab/opt/reboot.txt use crontab-e to edit scheduled operations. For example, add the following command: use the crontab-l command to check whether the service needs to be started (added to rc. local) restart the crond task/etc/init. d/cron restart (in ubuntu) first, in systems managed by RPM packages such as Fedora or Redhat; [root @ localhost ~] #/Etc/init. d/crond start [root @ localhost ~] #/Etc/init. d/crond stop [root @ localhost ~] #/Etc/init. d/crond restart/etc/rc. d/init. d/crond restart command overview crontab-operate the daemon of each user and the execution schedule. Some parameters indicate that crontab file [-u user]-replaces the current crontab with the specified file. Crontab-[-u user]-replace the current crontab with the standard input. crontab-1 [user]-list the current crontab of the user. crontab-e [user]-edit the current crontab of the user. crontab-d [user]-delete the current crontab of the user. crontab-c dir-specifies the crontab directory. Crontab file format: m h d m d cmd. M: minute (0-59 ). H: hour (0-23 ). D: Day (1-31 ). M: Month (1-12 ). D: days in a week (0 ~ 6, 0 is Sunday ). The program to be run by cmd is sent to sh for execution. The shell contains only three environment variables: USER, HOME, and SHELL.

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.