linux 7 定时任务设置,centos7 配置crontab定时任务
1. 啟動(dòng)cron服務(wù)
# 查看服務(wù)狀態(tài)
systemctl status crond
# 啟動(dòng)
systemctl start crond
# 停止
systemctl stop crond
# 重啟
systemctl restart crond
# 重新加載
systemctl reload crond
2. 開(kāi)機(jī)自動(dòng)啟動(dòng)cron服務(wù)
systemctl start crond.service
3. 通過(guò)crontab命令管理定時(shí)任務(wù)
crontab命令用法如下:
Usage:
crontab [options] file
crontab [options]
crontab -n [hostname]
Options:
-u define user
-e edit user's crontab
-l list user's crontab
-r delete user's crontab
-i prompt before deleting
-n set host in cluster to run users' crontabs
-c get host in cluster to run users' crontabs
-s selinux context
-x enable debugging
4. 定時(shí)任務(wù)格式
查看/etc/crontab文件,里面有格式說(shuō)明:
# 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
# [分] [時(shí)] [日] [月] [周] [需要執(zhí)行的命令]
詳細(xì)的cron表達(dá)式可以查看這篇文章:
5. 添加一個(gè)定時(shí)任務(wù)
# 進(jìn)入編輯模式,按照格式添加,保存退出
# crontab會(huì)自動(dòng)檢查語(yǔ)法是否正確,如果錯(cuò)誤會(huì)有提示。
[root@localhost /]# crontab -e
*/1 * * * * /home/app/zipkin/zipkin-dependencies.sh
*/1 * * * *:表示每分鐘執(zhí)行一次
/home/app/zipkin/zipkin-dependencies.sh:是需要執(zhí)行的命令
添加成功后,查看定時(shí)任務(wù)列表:
[root@localhost /]# crontab -l
*/1 * * * * /home/app/zipkin/zipkin-dependencies.sh
6. 查看執(zhí)行日志
cat /var/log/cron
總結(jié)
以上是生活随笔為你收集整理的linux 7 定时任务设置,centos7 配置crontab定时任务的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php hmac sha256签名,HM
- 下一篇: linux 其他常用命令