Crontab run every 15 minutes except at 3AM?

Is it possible to have a cronjob run every 15 minutes (over every hour etc..) except for at 3AM?

I have another special cronjob I want to run at 3AM, but I don't want the other one to run at the same time...


Solution 1:

With one cron line, no. With three, yes:

# Every 15 minutes except for 3:00-3:59
*/15 0-2,4-23 * * * thejob
# 3:15, 3:30, 3:45
15-45/15 3 * * * thejob
# 3:00 dead
0 3 * * * otherjob

Solution 2:

I made my own solution, but I wanted to see what other people thought of!

I put this on the top of my desired script. I wanted it to not run at the half hour either so it doesn't do it on both.

On top of the script:

if [ $(date +%M) = 00 ] || [ $(date +%M) = 30 ]
then
exit
fi

The cron line:

*/15 * * * * ~/path/to/file

Hope anyone uses my solution too.

Solution 3:

 0,15,30,45 0,1,2,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * * your cron job