Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of linux timing tasks crontabs installation and use

2025-01-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Install crontab

Yum install crontabs

Centos7 brought it with me. I didn't install it manually.

Start / close

Service crond start / / start service service crond stop / / close service service crond restart / / restart service service crond reload / / reload configuration

Check to see if the crontab service is set to boot

Systemctl list-unit-files | grep enable | grep crond

Add crontab to boot and start automatically

Chkconfig crond on// or systemctl enable crond.service

View crontab status

Service crond status / / View crontab service status

Write a scheduled task command format

Min hour day month dayofweek command time-sharing, days, months, days and days of the week order

​ min: the minute of each hour to execute the task; value range: 0-59

​ hour: the number of hours of the day to perform the task; value range: 0-23

​ day: perform this task on the day of each month; value range: 1-31

​ month: the month in which the task is performed; value range: 1-12

​ dayofweek: the day on which the task is performed; the value range is 0-6. 0 indicates the weekend.

​ command: specify the command to execute

Edit command in two ways: crontab-e and then add the corresponding task, wq save disk exit directly edit / etc/crontab file, that is, vi / etc/crontab, add the corresponding task time format

​ *: indicates any time; for example, hour bit * means every hour

​ n: indicates a specific moment; for example, 5 hours means 5 hours.

​ nrecom: indicates specific moments; for example, the hour position 1pm 10 means 1 and 10:00

​ NMurm: indicates a time period; for example, hour 1-5 indicates 1-5 o'clock.

​ / n: indicates the number of time units at which to execute; for example, the hour bit / 1 means that the command is executed every one hour, or it can be written as 1-23 bit 1.

Little chestnut.

* 1 * ~ / clear_cache.sh: execute the script every 1 minute from 1:00 to 1:59 0 * ~ / clear_cache.sh: execute the script every 0 minutes of the hour * / 10 * ~ / clear_cache.sh: execute the script every 10 minutes

Script to clean up the system cache

Code:

Vim ~ / clear_cache_logs.txtsudo sysctl-w vm.drop_caches=3sudo sysctl-w vm.drop_caches=1echo `date-R` > ~ / clear_cache_logs.txtfree-lh > > ~ / clear_cache_logs.txt

Clean the memory cache, and input the cleaning time and memory remaining log into the ~ / clear_cache_logs.txt file for easy viewing. You can do the scheduled task of cleaning the memory cache regularly in combination with crontab.

Summary

The above is the editor to introduce to you the detailed explanation of linux timing tasks crontabs installation and use, I hope to help you, if you have any questions, please leave me a message, the editor will reply to you in time. Thank you very much for your support to the website!

If you think this article is helpful to you, you are welcome to reprint it, please indicate the source, thank you!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report