2 ms·
I use fragments of this POSIX shell script for cron, to specify that I only want processing on a specific Thursday as defined by GNU date. These were the Thurs
by chasil 5y ago
I use fragments of this POSIX shell script for cron, to specify that I only want processing on a specific Thursday as defined by GNU date.
These were the Thursdays for July of 2021 (pick any Thursday to see them all).
$ ./monthday.sh 7 15
1 8 15 22 29
$ cat monthday.sh
#!/bin/dash
m="$1" d="$2" w=$(date +%u -d $m/$d) d=$(date +%u -d $m/1)
[ $w -lt $d ] && c1=$((8 - d + w)) || c1=$((w - d + 1))
c2=$((c1 + 7)) c3=$((c1 + 14)) c4=$((c1 + 21)) c5=$((c1 + 28))
{ date -d $m/$c5 || c5=0; } > /dev/null 2>&1
echo $c1 $c2 $c3 $c4 $c5