前言:Linux添加定時任務需要依賴crond服務,如果沒有該服務,需要先安裝:yum -y install crontabs
1、crond服務相關命令介紹
????????啟動crond服務:service crond start
????????停止crond服務:service crond stop
????????重啟crond服務:service crond restart
????????重載crond服務配置:service crond?reload
????????查看crond服務狀態(tài):service crond status
????????查看定時任務執(zhí)行狀態(tài):tailf?/var/log/cron
????????查看定時任務配置:crontab -l
????????修改定時任務配置:crontab -e
2、定時任務相關配置
2.1、定時任務配置格式
[root@test ~]# vim /etc/crontab
SHELL=/bin/bash #執(zhí)行命令的解釋器
PATH=/sbin:/bin:/usr/sbin:/usr/bin #環(huán)境變量
MAILTO=root #郵件發(fā)給誰
# 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 #星期
# | | | | |
# * * * * * command to be executed
# * 表示任意的(分、時、日、月、周)時間都執(zhí)行
# - 表示一個時間范圍段, 如5-7點
# , 表示分隔時段, 如6,0,4表示周六、日、四
# /1 表示每隔n單位時間, 如*/10 每10分鐘
2.2、配置舉例文章來源:http://www.zghlxwxcb.cn/news/detail-569931.html
00 02 * * * ls #每天的凌晨2點整執(zhí)行
00 02 1 * * ls #每月的1日的凌晨2點整執(zhí)行
00 02 14 2 * ls #每年的2月14日凌晨2點執(zhí)行
00 02 * * 7 ls #每周天的凌晨2點整執(zhí)行
00 02 * 6 5 ls #每年的6月周五凌晨2點執(zhí)行
00 02 14 * 7 ls #每月14日或每周日的凌晨2點都執(zhí)行
00 02 14 2 7 ls #每年的2月14日或每年2月的周天的凌晨2點執(zhí)行
*/10 02 * * * ls #每天凌晨2點,每隔10分鐘執(zhí)行一次
* * * * * ls #每分鐘都執(zhí)行
00 00 14 2 * ls #每年2月14日的凌晨執(zhí)行命令
*/5 * * * * ls #每隔5分鐘執(zhí)行一次
00 02 * 1,5,8 * ls #每年的1月5月8月凌晨2點執(zhí)行
00 02 1-8 * * ls #每月1號到8號凌晨2點執(zhí)行
0 21 * * * ls #每天晚上21:00執(zhí)行
45 4 1,10,22 * * ls #每月1、10、22日的4:45執(zhí)行
45 4 1-10 * * l #每月1到10日的4:45執(zhí)行
3,15?8-11?*/2?*?*?ls #每隔兩天的上午8點到11點的第3和第15分鐘執(zhí)行
0?23-7/1?*?*?*?ls #晚上11點到早上7點之間,每隔一小時執(zhí)行
15 21 * * 1-5 ls #周一到周五每天晚上21:15執(zhí)行
3、用定時任務執(zhí)行shell腳本文章來源地址http://www.zghlxwxcb.cn/news/detail-569931.html
?*/1?*?*?*?*?cd?/opt/app/test/bin/?&&?./task_test.sh
到了這里,關于Linux 環(huán)境使用定時任務執(zhí)行shell腳本的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!