On 03.07.2014 15:14, Adam Funk wrote:
> Background: I'm fiddling with a cron.daily job that I want to run on
> alternate days, so I want to test the output of `date +%j` for
> evenness.
Some crons already allow a finer time specification, includnig "every other"
instances of time. From my man page...
Step values can be used in conjunction with ranges. Following a range
with ``/<number>'' specifies skips of the number's value through the
range. For example, ``0-23/2'' can be used in the hours field to spec‐
ify command execution every other hour (the alternative in the V7 stan‐
dard is ``0,2,4,6,8,10,12,14,16,18,20,22''). Steps are also permitted
after an asterisk, so if you want to say ``every two hours'', just use
``*/2''.
>
> I figured the best way to check my if-test would be to use +%s, so I
> wrote the following (/bin/sh is dash on my system, but I could use
> another shell if it would be useful):
With modern shells (ksh, zsh, bash) you can force decimal interpretation
of numbers by preceding them with "10#", as in SEC=10#$( date +%S ) .
Janis