Linux centos7 通过shell脚本添加crontab任务

时间:2025-05-13 08:21:50
#!/bin/bash install_dir='/home/catic' # restart定时任务 echo "start deploy crotab for restart定时任务" # 判断文件夹是否存在 if [ ! -e /var/spool/cron/ ];then mkdir -p /var/spool/cron/ fi # 添加定时任务:每天凌晨1点1分停止服务与1点2分启动服务 if [ `grep -v '^\s*#' /var/spool/cron/root |grep -c '/data/socket'` -eq 0 ];then echo "* 1 1 * * sh $install_dir/" >> /var/spool/cron/root echo "* 2 1 * * sh $install_dir/" >> /var/spool/cron/root fi