Linux服务器Crontab定时任务配置
–>
1、检查linux系统是否有crontab
rpm -qa | grep crontab
2、如果未安装进行安装
yum -y install vixie-cron
yum -y install crontabs
3、crontab启动、停止、运行状态
systemctl start crond 启动
systemctl stop crond 停止
systemctl status crond 查看运行状态
systemctl restart crond 重新启动
4、查看crontab下有无定时任务
crontab -l
5、新增定时任务
crontab -e
执行命令后输入内容填写任务执行频率、任务脚本:
*/1 * * * * sh /task/task.sh >> /task/task.log # 每分钟执行task.sh
6、编写Shell任务脚本
status=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1/list) # echo $status >> task.log success=200 if (($status == $success)); then echo $(date "+%Y-%m-%d %H:%M:%S") ":服务正常" echo $(date "+%Y-%m-%d %H:%M:%S") ":服务正常" >> task.log fi if (($status != 200)); then echo $(date "+%Y-%m-%d %H:%M:%S") ":服务异常,准备重启..." echo $(date "+%Y-%m-%d %H:%M:%S") ":服务异常,准备重启..." >> task.log source /001/java2010/reload.sh fi
7、重启crontab
systemctl restart crond
此时任务就在按照编写的频率执行了。可以定时重启系统,定时删除日志,定时检查服务是否正常运行等
原文链接:https://www.cnblogs.com/sun-10387834/p/17997571
本文来源 互联网收集,文章内容系作者个人观点,不代表 本站 对观点赞同或支持。如需转载,请注明文章来源,如您发现有涉嫌抄袭侵权的内容,请联系本站核实处理。
© 版权声明
文章版权归作者所有,未经允许请勿转载。