Mt Xia: Technical Consulting Group

Business Continuity / Disaster Recovery / High Availability
Data Center Automation / Audit Response / Audit Compliance

-
Current Location
-

css
  GlobalSysAdmin
    AIX

-

digg Digg this page
del.icio.us Post to del.icio.us
Slashdot Slashdot it!


Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

FREE Domain Registration
included with Web Site Hosting
Tools, Social Networking, Blog

www.siteox.com

The following as a Korn shell function to determine if a specified year is a leap year.


#!/bin/ksh
################################################################
####    Korn Shell function to determine whether or not a specified
####    4 digit year is a leap year.  This function is designed to
####    return the result as the return status of the function.
####    The isLeap function returns 0 if the year is a leap year,
####    and 1 if it is not a leap year.
####
####    Load this file into your current environment as follows:
####    
####    . ./isLeap.ksh
####    
####    Thats "dot-space-dot-slash-isLeap-dot-ksh"
####
####    You will then be able to issue the command "isLeap"
####    from your current environment.
####
####    SYNTAX: isLeap [-d] [-y ####]
####
####                   -d    print the number of days in february to STDOUT
####
####                   -y    Require a 4 digit year to be specified.  
####                         performs leap year test against specified year.
####
####    AUTHOR: Dana French
####    EMAIL: dfrench@mtxia.com
####
################################################################
function isLeap {

STATUS="-1"
DFLAG=""
YFLAG=""
YEAR=`date +"%Y"`
while getopts ':dy:' NAME
do
    case "_${NAME}" in
        "_d") DFLAG="1";;
        "_y") YFLAG="1"; YEAR="${OPTARG}";;
        "_?") print "
SYNTAX: isLeap [-d] [-y ####]

        -d    print the number of days in february to STDOUT

        -y    Require a 4 digit year to be specified.  
              performs leap year test against specified year.

"; return ${STATUS};;
esac
done

if [[ "_${YEAR}" != "_" && ${#YEAR} -eq 4 ]]
then

    STATUS="1"
    [[ $(( ${YEAR} % 4 )) -eq 0 && $(( ${YEAR} % 100 )) -ne 0 ]] ||
    [[ $(( ${YEAR} % 400 )) -eq 0 ]] && STATUS="0"

    if [[ "_${DFLAG}" != "_" &&  "_${DFLAG}" = "_1" && "_${STATUS}" = "_0" ]]
    then
        print "29"
    fi
    if [[ "_${DFLAG}" != "_" &&  "_${DFLAG}" = "_1" && "_${STATUS}" = "_1" ]]
    then
        print "28"
    fi
else
    print "ERROR: Invalid year specified"
fi
return ${STATUS}
}

-
Leap Year Function
-
 


FREE Domain Registration
included with Web Site Hosting
Tools, Social Networking, Blog

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com