Friday, February 18, 2022

[SOLVED] Run a cron job on the odd day of the month on Tuesday?

Issue

I'm new in bash scripting. I need to run the job every Tuesday if the day of the month is odd. I need something like this to check conditions: [$(date '+%d') is odd ] && ...job...

But I cannot find how to check if the day is odd (

Thanks for helping


Solution

if expr $(date +%d) % 2 > /dev/null; then
    echo the day is odd
else
    echo the day is even
fi

Or, if you want to be slightly less old-fashioned:

if (( $(date +%d) % 2 )); then echo odd; else echo even; fi


Answered By - William Pursell
Answer Checked By - Cary Denson (WPSolving Admin)