Details the installation and use of linux timer task crontabs
- 2021-06-28 14:50:52
- OfStack
Install crontab
yum install crontabs
centos7 comes with me and I did not install it manually
Start/Close
service crond start // Start Services service crond stop // Shut down services service crond restart // Restart Service service crond reload // service crond reload
Check if the crontab service is set to start on
systemctl list-unit-files | grep enable | grep crond
Add crontab to Startup Autostart
chkconfig crond on
// perhaps
systemctl enable crond.service
View crontab status
service crond status // See crontab Service Status
Write timed task command format
min hour day month dayofweek command
branch time day month What day is today? command
&8203;min: Perform the task at the minute of every hour;Value range 0-59
&8203;hour: Perform this task for the first few hours of the day;Value range 0-23
&8203;day: Perform the task on the day of each month;Value range 1-31
&8203;month: Perform this task in the month of each year;Value range 1-12
&8203;dayofweek: Perform the task on the day of the week;Value range 0-6, 0 means weekend
&8203;command: Specify the command to execute
Edit commands by entering them on the command line in two ways:
crontab -e
Then add the corresponding task, wq exits direct editing
/etc/crontab
File, that is
vi /etc/crontab
Add the appropriate task time format
& #8203; *:Represents an arbitrary moment;Hour digits * denote every hour
&8203;n: Represents a specific moment;If hour 5 means hour 5
&8203;n, m: Represents a specific moment;If hour 1,10 means hour 1 and hour 10
&8203;n-m: Represents a time period;Hour digits 1-5 represent 1-5
& #8203; /n: Represents how many units of time are executed once;Hour bits/1 means that commands are executed every 1 hour, or 1-23/1
Chestnut
* 1 * * * ~/clear_cache.sh : From 1:00 reach 1:59 every other 1 Minute execution 1 Sub-script
0 * * * * ~/clear_cache.sh : Hourly 0 Minute execution 1 Sub-script
*/10 * * * * ~/clear_cache.sh : every 10 Sub-execution 1 Sub-script
Script to clean up system cache
Code:
vim ~/clear_cache_logs.txt
sudo sysctl -w vm.drop_caches=3
sudo sysctl -w vm.drop_caches=1
echo `date -R` >> ~/clear_cache_logs.txt
free -lh >> ~/clear_cache_logs.txt
Clean up memory
cache
And enter the cleanup time and memory leftover logs into the
~/clear_cache_logs.txt
Files, easy to view, can be combined
crontab
Schedule memory cleanup
cache
Timed tasks of.
summary