0 8 * * 6 test $((10#$(date +\%W)\%2)) -eq 1 && yourCommand
date +%W: week number of year with Monday as first day of week, today week 39
10#$(date +%W): conver the date +W to decimal number and avoid shell base parsing confusion
$((39%2)): modulo operation: result is 0 (even week number) or 1 (odd week number), this week result is 1, next week 0
test 1 -eq 1: arithmetic test (equal), in this case result is boolean true
&& yourCommand: Boolean AND: run yourCommand only if result of previous command was boolean true
Note that the year can get two odd weeks: 53 (this year) and 1 (next year)
the script does not run but if I write * * * * 5 /u02/restore/scripts/test.sh script runs.
why is your expression not working? I was just testing the cases.And found that not working somehow.
– kupa Oct 03 '14 at 12:320 8 * * 6 test $(($(date +\%W)\%2)) -eq 1 && yourCommand– Cyrus Oct 03 '14 at 13:07$((10#$(date +%W)%2)) -eq 1 && echo OKmy shell tries to execute the result of the week calculation :-bash: 1: command not found. Any clue why it's doing that ? Thanks. – jhuet Mar 31 '17 at 12:35testis no user it‘s a command. Try:test $((10#$(date +\%W)%2)) -eq 1 && echo odd || echo even– Cyrus Mar 31 '17 at 18:23/bin/sh: 1: arithmetic expression: expecting EOF: "10#11%2"– Redsandro Mar 19 '21 at 16:46