I need your help to contruct a cron job to run the second last working day of every month. I can do LW as shown below but i am not sure how to do second last. I need your help and advise here please.
@MWE has kindly provided me a possible solution but it does not seem to work in all test scenarios.
code:
#!/bin/bash
date
WEEKDAY=$(date +%u)
# If detect the montday in 2 days.
if [ $(date +%d -d "2 day") -eq 1 ] && [ ${WEEKDAY} -lt 5 ] ; then
echo "This is the 2. last working day of the month"
# If detect the montday in 5 days.
elif [ $(date +%d -d "5 day") -eq 1 ] && [ ${WEEKDAY} -eq 5 ] ; then
echo "This is the 2. last working day of the month"
else
exit
fi
Test scenario: Ive amended the system date on the server to be 29th August 2019 (**this is the second last working date on the system)
the script in debug mode exits out:
[oracle@rdbauroral01v ~]$ bash -x ./crontest.sh
+ date
Thu Aug 29 13:28:20 UTC 2019
++ date +%u
+ WEEKDAY=4
++ date +%d -d '2 day'
+ '[' 31 -eq 1 ']'
++ date +%d -d '5 day'
+ '[' 03 -eq 1 ']'
+ exit
appreciate your help here..