Operating System - HP-UX
1832927 Members
2789 Online
110048 Solutions
New Discussion

Re: Script for last working day of the month

 
SOLVED
Go to solution
Alex Grigore
Advisor

Script for last working day of the month

Hi guys,

Could you guide me into creating a script that will verify if the current day is the last working day of the month - and if yes, then do some other command.

I use a platform with HP-UX 11i.

Thank you in advance,
Alex.
4 REPLIES 4
Mel Burslan
Honored Contributor

Re: Script for last working day of the month

for any kind of date calculation, you can use Clay's date hammer, which can be obtained from:

http://mirrors.develooper.com/hpux/caljd-2.23.sh

and give it a test run. You may need to do some additional testing on the output like how many more days in this month and if this is the last friday or incorporate a company holiday calendar into it etc. Everyone's need is different but this script is always a very good starting point.
________________________________
UNIX because I majored in cryptology...
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Script for last working day of the month

First download the attached script caljd.sh.
By last working day of the month, I assume you mean if tomorrow skipping past weekends is a new month then today is the last working day of the month.

#!/usr/bin/sh

if [[ $(caljd.sh -M -n 1 -x 6 -x 0) -ne $(caljd.sh -M) ]]
then
echo "Last working day of the month; do your thing"
else
exit 0
fi

Now, if you will bring your /etc/acct/holidays file up to date, it's even smart enough to know about them and your command becomes:
#!/usr/bin/sh

if [[ $(caljd.sh -M -n 1 -x 6 -x 0 -h) -ne $(caljd.sh -M) ]]
then
echo "Last working day of the month; do your thing"
else
exit 0
fi

Invoke as caljd.sh -u for full usage and many examples.
If it ain't broke, I can fix that.
Alex Grigore
Advisor

Re: Script for last working day of the month

Thanks Clay, Mel for your answers.

As I'm kind of new to this "scripting stage" it will take me a while to understand your script Clay :)

Anyway, it's a good thing I have whom to learn from.


Thanks again,
Alex.
Alex Grigore
Advisor

Re: Script for last working day of the month

Closing the thread.