How to run a cron job at every 5 hour interval

半世苍凉 提交于 2019-12-02 08:31:24

One option from this forum post on unix.com Run it every hour, and add to your script:

time_ct=$(cat /tmp/cron_time_ct)
if [ $time_ct -lt 5 ]
   then
     echo "Not yet time"
     time_ct=$((time_ct+1))
     echo $time_ct > /tmp/cron_time_ct
     exit
   else
     time_ct=0
     echo $time_ct > /tmp/cron_time_ct
fi
# rest of your task

I've done similar to do "every other monday" type logic. Running the script every monday and only allowing execution on every other one in the script.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!