- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to determine if this is the 5th Friday in a mo...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2003 08:17 AM
09-26-2003 08:17 AM
We do some special payroll processing during months which have a 5th Friday. I have found some methods to determine if this is the last Friday but nothing to tell me if this is the fifth Friday. To make things more complicated, our payroll processing is done on Mondays so I can't even use the date command. What I really need is a cron command that runs on Mondays that determines if there is a 5th Friday in this week. I'm stumped. Any ideas?
Thanks,
David
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2003 08:31 AM
09-26-2003 08:31 AM
Re: How to determine if this is the 5th Friday in a month?
Here is one way to do it with a little bit of a hack using the 'cal' command in a shell script. There are probably better ways to do it out there, but here is my quick take:
# Test for a fifth Friday in this month.
FIFTHFRI=$(cal 10 2003 | tail +7 | awk '{print $6}')
if [[ ! -z $FIFTHFRI ]]; then
echo "There is a fifth Friday this month on this date: $FIFTHFRI"
else
echo "There is no fifth Friday this month."
fi
You can use replace the 'cal 10 2003' with 'cal $1 $2' so that you can pass the month and year as parameters, or you can just make it 'cal | ' and use the current month.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2003 08:35 AM
09-26-2003 08:35 AM
Re: How to determine if this is the 5th Friday in a month?
call it with an argument of
date "+%d%m%y"
#!/usr/bin/perl
($day,$month,$year)=split ":",$ARGV[0];
$year+=2000;
@CAL=`cal $month $year`;
pop(@CAL);;
$LASTLINE=pop(@CAL);
($sun,$mon,$tue,$wed,$thu,$fri,$sat)=split " ",$LASTLINE;
if($mon=$day and $fri>0){
print "This is a fifth friday\n";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2003 08:43 AM
09-26-2003 08:43 AM
SolutionA question similar to yours came up a few days ago (although it was a 4th Friday, I think) and he could use the date command but anyway in response to his problem, I added a -N option to caljd.sh that will tell you the occurrence of a given weekday. e.g 1 for first, 2 for 2nd, ...
In your case, you would run a cron job EVERY Monday and then the job itself will determine if this is the 5th week.
if [[ $(caljd.sh -n 4 -N) -eq 5 ]]
then
echo "Do your thing"
fi
The idea is that we find the julian day 4 days from Monday (-n 4 or Friday) and then report the occurrence of THAT weekday.
You must use caljs.sh version 2.21; none of the earlier versions have '-N'. Also, make sure that caljd.sh is in your PATH --- which must be explicitly set in your cron'ed script ---- because cron has an intentionally very sparse environment.
Here's caljd.sh, Vrsn 2.21.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2003 08:44 AM
09-26-2003 08:44 AM
Re: How to determine if this is the 5th Friday in a month?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2003 08:46 AM
09-26-2003 08:46 AM
Re: How to determine if this is the 5th Friday in a month?
Just noticed that I got the argument wrong in my previous post.
The script should be called with
date "+%d:%m:%y"
It should be run on a Monday and will tell you if that week contains a Friday that is the fifth Friday of the month. Or it looks like it will to me :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2003 08:58 AM
09-26-2003 08:58 AM
Re: How to determine if this is the 5th Friday in a month?
Clay, is there an easy way to test to see if this really works? All I can test using your example appears to be the current date.
Thanks,
David
--- points to follow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2003 09:14 AM
09-26-2003 09:14 AM
Re: How to determine if this is the 5th Friday in a month?
caljd.sh -n 4 -N 10 27 2003 will test for Oct 10, 2003.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2003 03:20 AM
09-27-2003 03:20 AM
Re: How to determine if this is the 5th Friday in a month?
I'm an idiot, I meant to say that
caljd.sh -n 4 -N 10 27 2003
will test for 4 days after Oct 27, 2003 and return the occurrence of that weekday (Friday) with the month.