In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the planned task under linux-what is the scheduled task that is executed periodically, which has certain reference value and can be used for reference by friends who need it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.
User sets periodic scheduled task crontab
If the average user wants to set up periodic scheduled tasks, they need to use the command crontab. Like at, crontab also has a blacklist and whitelist, and the configuration files are-/ etc/cron.deny and / etc/cron.allow, respectively.
When the user sets a scheduled task, the task is logged to the / var/spool/cron directory as a text file.
# ll / var/spool/cron/total 4 Murrw-1 root root 98 Jul 28 03:58 root
About crontab, we only need to remember two commands
Crontab-e sets scheduled tasks
Crontab-l View scheduled tasks
The format of the scheduled task is as follows:
Basic format: timesharing date, month and week command range: [0-59] [0-23] [1-31] [1-12] [0-7]
In addition, we need to remember the meaning of a few special characters:
* indicates that any time is fine
That represents the meaning of the separated time period
-indicates a continuous period of time
/ n means every n unit interval
Let's take a look at the use of the above special characters through a few examples:
# execute the script to detect memory every 5 minutes * / n * / root/script/check_memory.sh# at 05:20 on the 1st of each month, restart the server 20 5 1 * * / usr/sbin/reboot
Configuration files / etc/crontab, / etc/cron.d/* of the system
With regard to periodic scheduled tasks, there are three main corresponding configuration files, which are
/ var/spool/cron/, is set for the user
/ etc/crontab, scheduled tasks for the system
/ etc/cron.d/ may have multiple scheduled tasks for a software or system, such as for a website, so it is recommended to create a new configuration file under the / etc/cron.d/ directory.
Crontab-e is designed for the user level, and for periodic tasks at the system level, it is recommended to write it in the / etc/crontal file or / etc/cron.d/ directory.
Let's look at the contents of the / etc/crontab file.
# cat / etc/crontab SHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=root# For details see man 4 crontabs# Example of job definition:#.-minute (0-59) # |.-hour (0-23) # | |.-day of month (1-31) # |.-month (1-12) OR jan Feb,mar,apr... # |.-day of week (0-6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# | | # * user-name command to be executed# * root/ usr/bin/date > > / root/cron.txt
As you can see, it's a little different from crontab-e, where you need to specify a user name.
Next, let's look at what files are in the / etc/cron.d/ directory.
# ll / etc/cron.dtotal 8, RW, RW, RMI, Rafe. 1 root root 128 Aug 3 2017 hourly sysstat RW-1 root root 235 Aug 3 2017 sysstat
If there is a website on the server, for this website, we need to back up the database and website files regularly, and we also need to process some data regularly, then we can create a related file in the / etc/cron.d/ directory. Let's look at the contents of the 0hourly file:
# Run the hourly jobsSHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=root01 * root run-parts / etc/cron.hourly
This script means that the script file in the / etc/cron.hourly directory is executed every hour.
It is estimated that sharp-eyed friends have found that in addition to the cron.hourly directory, there are also cron.daily, cron.monthly and cron.weekly directories. But there is a difference between the three directories, which are executed by anacron. This anacron means to wake up an unexecuted scheduled task and execute it. For example, when you use crontab-e to set up a scheduled task, because of shutdown or other reasons, a single task is not executed, so you can only miss it, but if you put the script in the / etc/cron.daily/ directory, as long as it is not executed, it will be executed even if the time passes.
Thank you for reading this article carefully. I hope the editor will share the planned tasks under linux-what are the scheduled tasks that are executed periodically? at the same time, I also hope that you can support us, pay attention to the industry information channels, and find out if you encounter problems. Detailed solutions are waiting for you to learn!
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.