Hello everyone, I am a studious junior. I haven’t blogged for a long time because I am too busy at work. . . .
1. The function of scheduled task crontab:
Usually everyone writes a script, puts it on the server, and lets it run at a fixed time every day. There is no need to execute it manually every day. What I usually run here is shell and python. Please note that the server must have a supporting environment for python.
2.crontab usage and syntax:
#登录服务器执行命令,进入到vim页面
crontab -e
#注意我这里是用root用户登陆服务器的,所以他执行的就是root用户的定时任务
#页面展示内容
*/10 * * * * /sbin/ntpdate 10.45.186.81 #时钟同步定时任务
08,28,48 * * * * sh /root/test.sh
#每个小时的08分,28分,48分执行sh脚本,该脚本放置的绝对路径/root/test.sh
#python例子
10 12 * * * python /root/record_pid.py
#每天的12点10分跑脚本
Grammar: 5 positions, minutes, hours, day, month, day of the week
Minutes: 0-59
Hours:0-23
Day (number): 1-31
Which month (month): 1-12
Day of the week (week): 1-7
Abbreviation: time-sharing day-month-week
some special symbols
* represents any number within the value range at this position
/ represents "every", example */10 * * * * Executed every 10 minutes
3. Save and view
编辑完 crontab任务后
:wq #保存退出
crontab -l
#查看你写的定时任务
It’s not easy for newcomers to create. If you think it’s good, please give it a thumbs up! ! !
Please indicate the source when reprinting!