Unix Holidays

By Sandra Henry-Stocker  Add a new comment

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!

    Add a comment

    Post a comment using one of these accounts
    Or join now
    At least 6 characters

    Note: Comment will appear soon after you have activated your account.
    Obscene/spam comments will be removed and accounts suspended.
    The information you submit is subject to our Privacy Policy and Terms of Service.

    ITworld LIVE

    IT Management/StrategyWhite Papers & Webcasts

    White Paper

    Evaluator Group: Storage Federation - IT Without Limits (Analysis of HP Peer Motion with Storage Federation)

    As the role of IT increases within organizations, the need to move data when and where it is needed is critical to support emerging business requirements. This has become increasingly difficult due to the huge growth of data volumes. This white paper sponsored by HP + Intel evaluates a solution that aims to enable the movement of data without physical limitations. Read now and see how this could enable agility and efficiency.

    White Paper

    ESG Lab Validation Report: HP Data Protector & Deduplication Solutions

    Many organizations have deployed disk-to-disk backup technologies to improve the speed and reliability of their backup and disaster recovery operations. A growing number of these now look to data deduplication to enhance retention periods and reduce costs. This ESG Lab Validation Report sponsored by HP + Intel examines a number of backup and recovery solutions and evaluates their ease of implementation as well as their ability to improve reliability and reduce costs.

    White Paper

    Business Value of Blade

    The nature of the blade platform makes system management, monitoring and provisioning easy and efficient. Access this resource to learn how blade migration will save your data center time and money while increasing performance.

    White Paper

    Accelerate time to application value

    For your IT organization to keep pace with the business, you need a new, faster approach to infrastructure deployment-an approach that increases agility and accelerates time to application value. That's HP Converged Systems. Built on Converged Infrastructure, these systems deliver the industry's first portfolio of pre-integrated, tested, and optimized infrastructure solutions for applications running in virtual, cloud, dedicated, or hybrid environments.

    White Paper

    Converged Infrastructure for Dummies

    As you know, everything is mobile, connected, interactive, and immediate. This is exactly why organizations need a highly agile IT infrastructure in order to keep pace with extreme fluctuations in business demand. This book will help you understand why infrastructure convergence has been widely accepted as the optimal approach for simplifying and accelerating your IT to deliver services at the speed of business while also shifting significantly more IT resources from operations to innovation.

    See more White Papers | Webcasts

    Ask a question

    Ask a Question