-4

Actually i have a bash script file and i want to execute it on the last thursday of every month please help me to find out the proper solution of that problem using bash scripting.

closed as off-topic by Diamant, Chopper3, Ward, MadHatter, yagmoth555 Mar 1 '16 at 21:43

  • This question does not appear to be about server, networking, or related infrastructure administration within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

3

The way I would tackle this is to run the script using cron every Thursday (day 4 of the week). I would then have my script determine if today was the last Thursday of the month by examining the month of next Thursday. If it is the same as the month for today then today is not the last Thursday of the month.

The date command is quite versatile. You can get the numeric value of a month using +%m format so the value for today is

date +%m
03

The date command can do addition too so

date +%m now+7days

will at the appropriate time return the numeric vaule of next month which is different from that of today.

-2

Assuming you don't care about holidays, you can add entry in crontab as below. Please note it's difficult to standardise because of February, which only has 28 days. So below script is assuming Thursday of 4th week of every month.

"minute" "hour" 22-28 * * /usr/bin/test $(date +%w) -eq 4 && "Your script"

With this script, usr/bin/test $(date +%w) -eq 4 will be executed first. And only when it returns no error, it will execute your script.

  • This fails for March, June, July, September and December 2016 all of which have a last Thursday later than 28th. – Iain Mar 1 '16 at 9:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.