Linux uses the Crontab command to implement timed restart

Source: Internet
Author: User
Article Title: Linux uses the Crontab command to implement timed restart. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Crontab is a program that conveniently executes a task in a scheduled (Cyclic) manner on unix/linux systems.
 
Use the cron service and use the service crond status to view the cron service status. If it is not started, the service crond start starts it,
 
The cron service is a regular execution service. You can use the crontab command to add or edit tasks that require scheduled execution:
 
Crontab-u // set a user's cron service. Generally, the root user needs this parameter when executing this command.
 
Crontab-l // list the details of a user's cron Service
 
Crontab-r // Delete the cron service of no user
 
Crontab-e // edit a user's cron Service
 
For example, to view your cron settings as root: crontab-u root-l
 
For another 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.
 
In vi editing mode, the edited content must conform to the following format: */1 ***** ls>/tmp/ls.txt
 
Edit the/etc/crontab file and add a line at the end: 30 5 * root init 6 so that the system is configured to automatically restart at every morning.
 
You need to set crond as a service automatically started after the system starts. You can add
 
Service crond start
 
If you need to load other services in the system, you can continue to add the startup commands for other services.
 
For example, service mysqld start
 
Basic usage:
 
1. crontab-l
 
List the current crontab task
 
2. crontab-d
 
Delete the current crontab task
 
3. crontab-e (crontab-r above solaris5.8)
 
Edit a crontab task and ctrl_D ends.
 
4. crontab filename
 
Use filename as the crontab task list file and load it
 
Crontab file format:
 
Rows in the crontab file are composed of six fields. Different fields are separated by spaces or the tab key. The first five fields specify the time when the command will be run.
 
Minutes (0-59)
 
Hour (0-23)
 
Date (1-31)
 
Month (1-12)
 
Day of the week (0-6, 0 indicates Sunday)
 
The 6th fields are strings to be executed at the appropriate time
 
Example:
 
# MIN HOUR DAY MONTH DAYOFWEEK COMMAND
 
#06:10 every morning
 
10 6 **** date
 
# Every two hours
 
0 */2 *** date (solaris 5.8 does not seem to support this method)
 
# Every two hours from PM to am, am
 
0 23-7/2, 8 **** date
 
# Am on the 4th day of each month and from Monday to Wednesday of each week
 
0 11 4 * mon-wed date
 
# A.m. of July
 
0 4 1 jan * date
 
Note: When Using crontab, the environment variables that can be accessed in the running script may not be consistent with those in the current test environment, it is safer to set the environment variable (export) in the running script program)
 
(1ndcreate a file named crond.txt as follows and restart it at 05:36 every morning.
 
36 5 * reboot
 
(2) upload to the/opt directory
 
(3) run the command
 
Crontab/opt/crond.txt
 
Crontab-l
 
Make the configuration file take effect: If the configuration file takes effect, you have to restart cron. Remember that 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: Check the cron service status. If it 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 tasks that require scheduled execution.

[1] [2] Next page

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.