In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the use of linux timing tasks, the content is clear, interested friends can learn, I believe it will be helpful after reading.
1. Cron introduction
What we often use is that the crontab command is the abbreviation for cron table, which is the configuration file of cron, or the job list, which we can find in the following folder.
1.1.The cron related catalogue
In the / var/spool/cron/ directory is the crontab task for each user, including root, and each task is named after the creator / etc/crontab. This file is responsible for scheduling various management and maintenance tasks. The / etc/cron.d/ directory is used to hold any crontab files or scripts to be executed. We can also put the script in the / etc/cron.hourly, / etc/cron.daily, / etc/cron.weekly, / etc/cron.monthly directory and have it executed hourly, daily, weekly, and monthly.
1.2.Common commands of crontab
Crontab [- u username] / / omit the user table means to operate the current user's crontabcrontab [- u username]-e / / edit the worksheet) crontab [- u username]-l / / list the commands in the worksheet) crontab [- u username]-r / / delete the work)
1.3. Write specifications
1. The relevant parameters for each location are shown in the figure below, as well as the details of remarks.
Note:
1) * means that any time (minute, hour, day, month, week) is executed
2)-represents a time range, such as 5-7 o'clock
3), which means separate periods, such as 6, 0, 4, which means Saturday, Sunday and Thursday.
4) / 1 means every n units of time, such as * / 10 every 10 minutes
2. Set scheduled tasks
2.1.Global setting scheduled task crontab-when the task is linked, curl, or written to a file
(1) execute the command crontab-e
(2) write scheduled tasks
If the task of running regularly is a link
* / 1 * / usr/local/curl (your own curl path) www.baidu.com > / dev/null 2 > $1
If you need to write the content to the file
* / 1 * echo "hello" > > abc.log
In addition, I need to popularize a few points.
Standard input 0 gets input from keyboard / proc/self/fd/0 standard output 1 output to screen (console) / proc/self/fd/1 error output 2 output to screen (console) / proc/self/fd/2/dev/null represents linux empty device file, all writes to this file will be lost The so-called "black hole" > / dev/null means to output the error to "black hole" > / dev/null 2 > & 1 by default, which is equivalent to 1 > / dev/null 2 > & 1. It means to redirect the standard output to the "black hole" and redirect the error output 2 to the standard output 1, that is, both the standard output and the error output go into the "black hole" 2 > & 1 > / dev/null means to redirect the error output 2 to the standard output 1, that is, the screen, the standard output goes into the "black hole", that is, the standard output goes into the black hole, and the error output is printed to the screen about the role of "&" here. We can understand that 2 > / dev/null redirects to a file, then 2 > & 1, if removed here & is to output the error to file 1, using & to indicate that 1 is standard output.
(3) Save timing tasks
Press I to insert operation, write scheduled task to exit by Esc and enter: wq, and then press Ctrl + C to save the success.
2. 2. Sh method implementation
(1) create a Shell script
Create a file with the suffix .sh in the project and add sufficient permissions to the shell file in that directory
Chmod-R 777 you create the file name
(2) write Shell script to scheduled task
Write the corresponding shell file to the scheduled task
* / 1 * absolute path to your .sh file > / dev/null 2 > $1
Write the corresponding shell file to the log when performing a scheduled task
* / 1 * absolute path to your .sh file > > a.log > / dev/null 2 > $1
(3) restart crond
Service crond restart
(4) check whether it is written into the project
After reading the above content, crontab-l has a further understanding of the use of linux scheduled tasks. If you want to learn more, you are 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.