execute crontab twice daily at 00h and 13:30

守給你的承諾、 提交于 2019-11-27 03:44:53

问题


i want to execute a script twice daily at 00:00 and 13:30 so i write :

0,30 0,13 * * *

it seems wrong for me, because like this, the script will fire at 00:00 , 00:30 , 13:00 and 13:30. Any idea ?


回答1:


Why not put in two cron entries ? One for 00:00 and one for 13:30 ? I don't think you can do what you want in one entry, since the two minute definitions will apply for both hour definitions (as you've identified).

The alternative is perhaps to execute one script at 00:00. That script would execute your original script, then wait 13.5 hours and then execute that script again. It would be easy to do via a simple sleep command, but I think it's unintuitive, and I'm not sure how cron manages such long running processes (what happens if you edit the crontab - does it kill a spawned job etc.)




回答2:


Try this-: 00 01,13 * * *

it will run at 1 A.M and 1 P.M




回答3:


You can not do that with cron on a single line. You have to create 2 separate lines like so:

# Will run "YourCommand" at 00:00
0   0   *   *   *   YourCommand
# Will run "YourCommand" at 13:30
30  13  *   *   *   YourCommand

Or as a single line you can run a command every x hours, like so:

# Will run "YourCommand" every 12 hours
0   */12   *   *   *   YourCommand



回答4:


try ...

00,30 00,13 * * * [ `date +%H%M` == 1330 ] || [ `date +%H%M` == 0000 ] && logger "its time"



回答5:


30 0,13 * * * somecommand.sh

This is just purely an example, but you will see that this is a cron entry that will run at 0:30AM and then 1:30PM (13 is 1 in military time). Just comma separate the hours, or comma separate whatever section of the cron.



来源:https://stackoverflow.com/questions/13993556/execute-crontab-twice-daily-at-00h-and-1330

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