I am trying to run a job on the first weekday of each month with the following crontab entries:
00 07 1-3 * * [ "$(date '+\%a')" == "Mon" ] && echo "Its Monday!"
00 07 1 * * [ "$(date '+\%a')" == "Tue" ] && echo "Its Tuesday!"
00 07 1 * * [ "$(date '+\%a')" == "Wed" ] && echo "Its Wednesday!"
00 07 1 * * [ "$(date '+\%a')" == "Thu" ] && echo "Its Thursday!"
00 07 1 * * [ "$(date '+\%a')" == "Fri" ] && echo "Its Friday!"
But this morning I got the following error:
/bin/sh: 1: [: Thu: unexpected operator
\%a
is probably to protect%
from cron, where%
indicates that what follows is to be the input for the command. http://askubuntu.com/a/106440/158442 – muru Dec 01 '16 at 10:15