In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use the crontab command in Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The common Linux command crontab is used to submit and manage tasks that users need to execute periodically, similar to the scheduled tasks under windows. When the installation of the operating system is completed, this service tool is installed by default, and the crond process is automatically started. The crond process periodically checks whether there is a task to be executed every minute, and automatically executes the task if there is a task to be executed.
Crontab submits and manages tasks that users need to perform periodically
Syntax crontab (options) (parameters) option-e: edit the user's timer settings;-l: list the user's timer settings;-r: delete the user's timer settings;-u: specify the name of the user to set the timer. Parameter crontab file: specifies the crontab file that contains the task to be performed.
Task scheduling under knowledge extension Linux can be divided into two categories: system task scheduling and user task scheduling.
System task scheduling: the work that the system periodically performs, such as writing cached data to the hard disk, log cleaning, etc. There is a crontab file in the / etc directory, which is the configuration file for system task scheduling.
The / etc/crontab file includes the following lines:
SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO= "" HOME=/ # run-parts 51 * root run-parts / etc/cron.hourly 24 7 * root run-parts / etc/cron.daily 22 4 * * 0 root run-parts / etc/cron.weekly 42 41 * * root run-parts / etc/cron.monthly the first four lines are the environment variables used to configure the crond task to run The first line of SHELL variable specifies which shell the system should use, here is bash, the second line of PATH variable specifies the path to which the system executes the command, the third line of MAILTO variable specifies that the task execution information of crond will be sent to the root user by email, if the value of the MAILTO variable is empty, the task execution information will not be sent to the user, and the HOME variable of the fourth line specifies the home directory to be used when executing the command or script.
User task scheduling: tasks that users perform on a regular basis, such as user data backup, scheduled email reminders, etc. Users can use the crontab tool to customize their scheduled tasks. All user-defined crontab files are saved in the / var/spool/cron directory. The file name is the same as the user name, and the user rights file is as follows:
/ etc/cron.deny the users listed in this file are not allowed to use the crontab command / etc/cron.allow the directory where the users listed in this file are allowed to use the crontab command / var/spool/cron/ all users' crontab files, the meaning of naming the crontab file after the user name: in the crontab file created by the user, each line represents a task, each field on each line represents a setting, and its format is divided into six fields The first five paragraphs are the time setting paragraph, and the sixth paragraph is the command paragraph to be executed, in the following format:
Minute hour day month week command order: time-sharing, day, month and week:
Minute: represents minutes and can be any integer from 0 to 59.
Hour: represents an hour, which can be any integer from 0 to 23.
Day: represents the date and can be any integer from 1 to 31.
Month: represents the month and can be any integer from 1 to 12.
Week: represents the day of the week, which can be any integer from 0 to 7, where 0 or 7 represents Sunday.
Command: the command to be executed can be a system command or a script file written by yourself.
The following special characters can also be used in each of the above fields:
Asterisk (*): represents all possible values. For example, if the month field is an asterisk, it means that the command operation is performed every month after the constraints of other fields are met.
Comma (,): you can specify a list range with values separated by commas, for example, "1, 2, 5, 7, 8, 9"
Middle bar (-): you can use the middle bar between integers to represent a range of integers, for example, "2-6" means "2pens 3pr 4je 5pl 6"
Forward slash (/): the interval frequency of the time can be specified with a forward slash, for example, "0-23gam2" indicates that it is executed every two hours. At the same time, a forward slash can be used with an asterisk, such as * / 10, which, if used in the minute field, means that it is executed every ten minutes.
Crond service
/ sbin/service crond start # start the service / sbin/service crond stop # shut down the service / sbin/service crond restart # restart the service / sbin/service crond reload # reload the configuration to view the crontab service status:
Service crond status manually starts the crontab service:
Service crond start checks to see if the crontab service is set to boot and execute the command:
Ntsysv joins boot and starts automatically:
Chkconfig-level 35 crond on instance executes command every 1 minute
* command executes at the 3rd and 15th minutes of each hour
3Jing 15 * command is executed in the 3rd and 15th minutes from 8am to 11:00
3 command 158-11 * the 3rd and 15th minutes from 8am to 11:00 every two days
3 command 158-11 * / 2 * * the 3rd and 15th minutes from 8am to 11:00 every Monday
3Jing 158-11 * * 1 command restarts smb at 21:30 every night
30 21 * / etc/init.d/smb restart restart smb at 4: 45 on the 1st, 10th and 22nd of each month
45-4-1-10-10-22 * * / etc/init.d/smb restart restart smb at 1:10 every Saturday and Sunday
10 1 * * 6 smb / etc/init.d/smb restart restart smb every 30 minutes between 18: 00 and 23: 00 every day
Etc/init.d/smb restart 30 18-23 * / pm restarts smb at 11:00 every Saturday night
023 * * 6 / etc/init.d/smb restart restart smb every hour
* * / 1 * / etc/init.d/smb restart restarts smb every other hour between 11:00 and 7am
* 23-7 etc/init.d/smb restart 1 * / smb restarts on the 4th of each month and at 11:00 from Monday to Wednesday
0 11 4 * mon-wed / etc/init.d/smb restart restart smb at 4: 00 on January 1st
0 4 1 jan * / etc/init.d/smb restart executes scripts in the / etc/cron.hourly directory every hour
01 * root run-parts / etc/cron.hourly above is all the content of this article "how to use crontab commands in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.