IT management/strategy

Unix Holidays

September 22, 2009, 01:23 PM — 

The /etc/acct/holidays file is intended to be used by various accounting utilities on your system that might need to behave differently on certain days of the year -- holidays. On one of my more recently installed systems, the holiday file looks like this:

* @(#)holidays  January 1, 2008
*
* Prime/Nonprime Table for UNIX Accounting System
*
* Curr  Prime   Non-Prime
* Year  Start   Start
*
  2008  0800    1800
*
* only the first column (month/day) is significiant.
*
* month/day     Company
*               Holiday
*
1/1             New Years Day
7/4             Indep. Day
12/25           Christmas

As the man page for the holidays file format describes, this file is meant to be updated annually and include details on which hours are considered prime time along with which days are considered holidays. I have to be grateful that files like this don't have any say in which days I enjoy a paid day off! But you can easily update the holidays file to reflect holidays that your organization observes.

Another use of the holidays file is to curtail the behavior of cron jobs on days that you don't work. If you send out reminders to staff to clock their hours or turn off the coffee pot before they go home, you might want to avoid doing so on holidays.

To use the holidays file, you first have to make sure it reflects the current year. Federal holidays can be found here. So, say you update the holiday list to look like this:

1/1             New Years Day
1/19            MLK Day
2/16            Washington's birthday
5/25            Memorial Day
7/7             Indep. Day
9/22            Eid al-Fitr starts
9/23            Nici's (my daughter's) birthday
10/12           Columbus Day
11/11           Veterans Day
11/26           Thanksgiving
12/25           Christmas

Now all you have to do is figure out how to make use of the file! Obviously, it isn't heavily used or the out-of-date files on many of my systems would have raised a red flag long before now. But it's a standard file on Solaris, so we might as well use it. Here's a script which shows whether today is a holiday.

#!/bin/bash

grep -v "\*" /etc/acct/holidays > /tmp/$0

MO=`date +%m | sed "s/^0//"`
DAY=`date +%e`
TODAY="$MO/$DAY"

while read dt event
do
    if [ $dt == $TODAY ]; then
        echo "Yay!  Today is $event!  Go home!  Celebrate!"
    fi
done < /tmp/$0

rm /tmp/$0

The sed removal of leading zeroes is included in the fifth line because the date command doesn't have an option that displays the month in numeric form without leading zeroes for January through September. In the sixth line, we use the %e option with the date command to get just the day of the month in the single digit (if applicable) format. Some of the other useful date options are shown below.

opt: %A => Wednesday
opt: %B => September
opt: %C => Tue Sep 23 14:09:49 EDT 2009
opt: %D => 09/23/09
opt: %G => 2009
opt: %H => 14
opt: %I => 02
opt: %M => 09
opt: %R => 14:09
opt: %S => 50
opt: %T => 14:09:50
opt: %U => 38		(week number)
opt: %V => 39
opt: %W => 38
opt: %X => 14:09:50
opt: %Y => 2009
opt: %a => Tue
opt: %b => Sep
opt: %c => Tue Sep 23 14:09:50 2009
opt: %d => 23
opt: %e => 23
opt: %g => 09
opt: %h => Sep
opt: %j => 266
opt: %k => 14
opt: %l =>  2
opt: %m => 09
opt: %p => PM
opt: %r => 02:09:50 PM
opt: %u => 2
opt: %w => 2
opt: %x => 09/23/09
opt: %y => 09
opt: %z => %z

Here's a version of the script that you could refer to within cron jobs to determine whether the cron job should run normally or not:

#!/bin/bash

grep -v "\*" /etc/acct/holidays > /tmp/$0

MO=`date +%m | sed "s/^0//"`
DAY=`date +%e`
TODAY="$MO/$DAY"

while read dt event
do
    if [ $dt == $TODAY ]; then		# found today's date in the file
        exit 1
    fi
done < /tmp/$0

rm /tmp/$0

If the current day is a holiday, this script returns a 1 to warn the script not to run. It returns a 0 if it's a normal day. You could refer to it in a cron job like so:

/usr/local/bin/chkHoliday

if [ $? != 0 ]; then
    exit
fi

You might come up with other novel ways of using the holidays file. For example, you could come up with a script that tells you whether any holidays fall within the next two weeks. If you're anything like me and don't know about work holidays until one of your coworkers reminds you ("See you next week!" someone says. "Next week? Not tomorrow?" you reply. "Tomorrow's [insert holiday name here]", you workaholic dunce!"). Maybe you'll be the one that sees the holidays coming!

Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
peer-to-peer

Esther Schindler
If the comments are ugly, the code is ugly

claird
SVG a graphics format for 21st century

pasmith
Take Chrome OS for a test spin

Sandra Henry-Stocker
Solaris Tip: Have Your Files Changed Since Installation?

sjvn
64-bits of protection?

jfruh
Android fragments vs. the iPhone monolith

mikelgan
What Gizmodo missed about the Pro WX Wireless USB disk drive

 

Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325

Join the conversation here

The Daily Tip

The Daily TipQuick, practical advice for IT pros. Made fresh daily.

Hot tips:

Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.

Newsletters

Subscribe to ITWORLD TODAY and receive the latest IT news and analysis.

I would like to receive offers via email from ITworld partners.
By clicking submit you agree to the terms and conditions outlined in ITworld's privacy policy.
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace