- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- First work day in the month?
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
Discussions
Discussions
Forums
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
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
тАО05-14-2007 09:19 AM
тАО05-14-2007 09:19 AM
I have another problem. I need to know if today is the first work day of the month. For example, if the 1st was Saturday then Monday the 3rd would be the first work day. Any ideas?
Thank you,
Ryan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2007 09:23 AM
тАО05-14-2007 09:23 AM
Re: First work day in the month?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2007 09:31 AM
тАО05-14-2007 09:31 AM
SolutionI'll assume that you have been a good boy and set up /etc/acct/holidays and it's a better idea to set up multiple years by creating separate /etc/acct/holidays_YYYY because consider the problem of also crossing year boundaries and 1-Jan is a very common holiday.
I would set up a cron job that runs EVERY Monday-Friday (remember some folks have very long holidays) and then do this:
#!/usr/bin/sh
# first test to see if yesterday's month
# skipping past Sundays and Saturdays and
# holidays is not equal to today's month
if [[ $(caljd.pl -p 1 -x 0 -x 6 -h -M) != $(caljd.pl -M) ]]
then
# now check to see if today isn't also
# a holiday
if [[ $(caljd.pl) = $(caljd.pl -h) ]]
then
echo "Today is the first working day of the month."
fi
fi
Invoke as caljd.pl -u for full usage and examples. You should already have a copy of the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-14-2007 01:25 PM
тАО05-14-2007 01:25 PM
Re: First work day in the month?
But if you did, and did not count holidays, then the rule would appear to be:
It is the first workday in the month if it is the first of the months and not a Saturday nor Sunday or if it is a Monday and the 2nd or 3rd of the month.
In Perl:
my ($mday,$wday) = (localtime(time))[3,6];
print "YES\n" if (($mday==1 && $wday && $wday != 6) || ($mday < 4 && $wday == 1 ))
And in perl with taking a YYYYMMDD as argument:
--- test.pl ---
use Time::Local;
$x=shift;
$y=timelocal(0,0,0,substr($x,6,2),substr($x,4,2)-1,substr($x,0,4)-1900);
my ($mday,$wday) = (localtime($y))[3,6];
print "YES\n" if (($mday==1 && $wday && $wday != 6) || ($mday < 4 && $wday == 1 ))
----
perl test.pl 20070101
The first mondays in a month is a relatively popular holiday day!
fwiw,
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 12:03 AM
тАО05-15-2007 12:03 AM
Re: First work day in the month?
# start of SCHEDULE TEST
# 1. Have a $x1_listofdates in this program that gives a schedule.
# 2. Run the cronjob every day from 1st to 10th of the month.
# 3. Have the job exit out unless the day matches the schedule.
# note: typeset -i tells unix the value is an integer, not octal binary.
#------------------------------------------------------------------------------
typeset -i x1_day_of_month=`date +"%d"`
x1_month_of_year=`date +"%b"`
typeset -i x1_year=`date +"%Y"`
x1_datestring=`printf "%02d%s%4d\n" $x1_day_of_month $x1_month_of_year $x1_year`
# these days are when the script should run.
# they are the 2nd workday of each month.
x1_listofdates="
05Sep2007
02Oct2007
02Nov2007
04Dec2007
"
x1_FLAGRUN=0
echo "Run my special job today?"
for x1_D in $x1_listofdates
do
echo " today is $x1_datestring look at $x1_D from the list. "
if [ "$x1_D" = "$x1_datestring" ] ; then
echo "Yes. "
x1_FLAGRUN=1
else
echo "do not run today"
fi
done
if [ $x1_FLAGRUN != 1 ] ; then
echo "do not run today"
exit
fi
rest of program goes here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 12:09 AM
тАО05-15-2007 12:09 AM
Re: First work day in the month?
Of course if your schedule follows NO rules, this might be a good thing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 05:56 AM
тАО05-15-2007 05:56 AM
Re: First work day in the month?
http://www.unixreview.com/documents/s=1344/ur0309c/
That one links to this one, "The American Secular Holidays Calendar":
http://www.smart.net/%7Emmontes/ushols.html#ALG
It goes into great detail about "the first workday of a month", with all the exceptions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 09:02 AM
тАО05-15-2007 09:02 AM
Re: First work day in the month?
Thanks everyone for all the help. I am having a
little trouble making the holidays work as A. Clay correctly pointed out. I am getting this error message. "File /etc/acct/holidays year 1998 does not match expected year 2007".
Any ideas?
Thank you,
Ryan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 09:17 AM
тАО05-15-2007 09:17 AM
Re: First work day in the month?
Anyway, update the file with the current holidays and the current year and you should be fixed.
One of the changes to the holidays file convention I implemented for caljd.xx, is to add a year extension Caljd.xx will always try to find holidays_YYYY before it falls back on the default file. This way, date calculations involving holidays which cross year boundaries work as expected. I always symbolically link the current year's /etc/acct/holidays_YYYY to /etc/acct/holidays so that any other UNIX software works as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 10:36 AM
тАО05-15-2007 10:36 AM
Re: First work day in the month?
Thanks. I updated /etc/acct/holidays and now it works!. I deserved to be called stupid because the error message described the problem exactly.
Thank you,
Ryan
PS, It's time for points!