Currently I'm using /usr/bin/ifNotNearMidnight as:
#!/bin/bash
t=$(date +\%H\%M)
if [[ "$t" > 2350 ]] || [[ "$t" < 0010 ]]
then
exit 1
fi
And then in cron:
* * * * * ifNotNearMidnight && ( cd /blah/ ; doTheThing )
Currently I'm using /usr/bin/ifNotNearMidnight as:
#!/bin/bash
t=$(date +\%H\%M)
if [[ "$t" > 2350 ]] || [[ "$t" < 0010 ]]
then
exit 1
fi
And then in cron:
* * * * * ifNotNearMidnight && ( cd /blah/ ; doTheThing )
@artfulrobot FWIW, I find your current method cleaner and more readable, rather than trying to browbeat a crontab/systemd-timer into doing it.
The alternative might be something like (untested)
*/2 1-22 * * * do_thing
12-58/2 0 * * * do_thing
0-48/2 23 * * * do_thing
The duplication makes it harder to read/understand, the edge-cases are more prone to be off-by-one, the meaning isn't as clear, and updating any one of them involves possibly messing with the others.
@artfulrobot the only thing I'd change would be the first "*" since you said every 2 minutes, so it would be
*/2 * * * * do_thing
but I suspect that was just a typo/mistranscription and your crontab is already otherwise correct ☺