#!/bin/ksh93 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r714 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_fallback_timer.sh 1.4 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2010 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#)46 1.4 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_fallback_timer.sh, hacmp.assist, 61haes_r714 8/6/13 16:56:48 #================================================ # The following, commented line enforces coding # standards when this file is edited via vim. #================================================ # vim:tabstop=4:shiftwidth=4:expandtab:smarttab #================================================ # Start of POD-formatted documentation. Viewing suggestions: # perldoc # pod2text -c # pod2text -c --code # pod2html function devDoc { : <<'=cut' >/dev/null 2>&1 =head1 NAME KLIB_HACMP_modify_fallback_timer =head1 VERSION Version Number: 1.4 Last Extracted: 1/31/14 04:41:08 Last Changed: 8/6/13 16:56:48 Path, Component, Release(, Level): src/43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_fallback_timer.sh, hacmp.assist, 61haes_r714 =head1 SYNOPSIS clmgr modify fallback_timer \ [ YEAR=<{####}> ] \ [ MONTH=<{1..12 | Jan..Dec}> ] \ [ DAY_OF_MONTH=<{1..31}> ] \ [ DAY_OF_WEEK=<{0..6 | Sun..Sat}> ] \ [ HOUR=<{0..23}> ] \ [ MINUTE=<{0..59}> ] \ [ REPEATS=<{0,1,2,3,4 | Never,Daily,Weekly,Monthly,Yearly}> ] NOTE: aliases for "fallback_timer" are "fa" and "timer". =head1 DESCRIPTION Attempts to modify the specified fallback timer to conform to the provided specifications. =head1 ARGUMENTS 1. properties [REQUIRED] [hash ref] An associative array within which data about the modified object can be returned to the caller. 2. timer [REQUIRED] [string] The label of the fallback timer that is to be modified. 3. year [OPTIONAL] [integer] The year when this timer should be invoked. NOTE: the presence of this value implies a non-repeating timer. 4. month [OPTIONAL] [integer] The month when this timer should be invoked. NOTE: the presence of this value implies a timer that repeats yearly. 5. day_of_month [OPTIONAL] [integer] The day of the month when this timer should be invoked. NOTE: the presence of this value implies a timer that repeats monthly. 6. day_of_week [OPTIONAL] [integer] The day of the week when this timer should be invoked. NOTE: the presence of this value implies a timer that repeats weekly. 7. hour [REQUIRED] [integer] The hour when this timer should be invoked. 8. minute [REQUIRED] [integer] The minute when this timer should be invoked. 9. repeats [OPTIONAL ] [string] The frequency with which the time should be repeated. This is automatically set at timer creation time, and is only exposed here so that the frequency can be explicitly changed. =head1 RETURN 0: no errors were detected; the operation appears to have been successful 1: a general error has occurred 2: a specified resource does not exist, or could not be found 3: some required input was missing 4: some detected input was incorrect in some way 5: a required dependency does not exist 6: a specified search failed to match any data =head1 COPYRIGHT COPYRIGHT International Business Machines Corp. 2005,2010 All Rights Reserved =cut } # End of POD-formatted documentation. function KLIB_HACMP_modify_fallback_timer { LINENO=2 . $HALIBROOT/log_entry "$0()" "$CL" : version=1.4, src/43haes/lib/ksh93/hacmp/KLIB_HACMP_modify_fallback_timer.sh, hacmp.assist, 61haes_r714 : INPUTS: $* typeset -n properties=$1 typeset timer=${2//\"/} shift; shift typeset year=${1//\"/} typeset monthStr=${2//\"/} typeset day_of_month=${3//\"/} typeset day_of_weekStr=${4//\"/} typeset hour=${5//\"/} typeset minute=${6//\"/} typeset repeats=${7//\"/} [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #================================================================ : Check for a defined cluster. No need to continue without one. #================================================================ CL=$LINENO isClusterDefined if (( $? != RC_SUCCESS )); then log_return_msg "$RC_MISSING_DEPENDENCY" "$0()" "$LINENO" return $? fi #=================================== : Declare and initialize variables #=================================== typeset -i rc=$RC_UNKNOWN typeset -A timer_attrs= typeset -i i=0 typeset JAN= FEB= MAR= APR= MAY= JUN= JUL= AUG= SEP= OCT= NOV= DEC= typeset MONTHS=$(/usr/bin/dspmsg -s 36 cluster.cat 15 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec') print -- "$MONTHS" | IFS=, read JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC REM typeset -l JAN_LC=$JAN typeset -l FEB_LC=$FEB typeset -l MAR_LC=$MAR typeset -l APR_LC=$APR typeset -l MAY_LC=$MAY typeset -l JUN_LC=$JUN typeset -l JUL_LC=$JUL typeset -l AUG_LC=$AUG typeset -l SEP_LC=$SEP typeset -l OCT_LC=$OCT typeset -l NOV_LC=$NOV typeset -l DEC_LC=$DEC typeset -i month=-1 if [[ -n $monthStr ]]; then if [[ $monthStr == +([[:digit:]]) ]]; then if (( monthStr >= 1 && monthStr <= 12 )); then (( month = $monthStr - 1 )) else CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 "\nERROR: invalid value specified for \"%1\$s\": \"%2\$s\"\n\n" MONTH "$monthStr" 1>&2 CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 "Valid values: %1\$s\n\n" "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12" 1>&2 rc=$RC_INCORRECT_INPUT fi else typeset -l monthStr_lc=$monthStr case $monthStr_lc in $JAN_LC) month=0 ;; $FEB_LC) month=1 ;; $MAR_LC) month=2 ;; $APR_LC) month=3 ;; $MAY_LC) month=4 ;; $JUN_LC) month=5 ;; $JUL_LC) month=6 ;; $AUG_LC) month=7 ;; $SEP_LC) month=8 ;; $OCT_LC) month=9 ;; $NOV_LC) month=10 ;; $DEC_LC) month=11 ;; *) CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 "\nERROR: invalid value specified for \"%1\$s\": \"%2\$s\"\n\n" MONTH "$monthStr" 1>&2 CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 "Valid values: %1\$s\n\n" "$JAN, $FEB, $MAR, $APR, $MAY, $JUN, $JUL, $AUG, $SEP, $OCT, $NOV, $DEC" 1>&2 rc=$RC_INCORRECT_INPUT ;; esac fi fi typeset SUNDAY= MONDAY= TUESDAY= WEDNESDAY= THURSDAY= FRIDAY= SATURDAY= typeset DAYS=$(/usr/bin/dspmsg -s 36 cluster.cat 16 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday') print -- "$DAYS" | IFS=, read SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY REM typeset -l SUNDAY_LC=$SUNDAY typeset -l MONDAY_LC=$MONDAY typeset -l TUESDAY_LC=$TUESDAY typeset -l WEDNESDAY_LC=$WEDNESDAY typeset -l THURSDAY_LC=$THURSDAY typeset -l FRIDAY_LC=$FRIDAY typeset -l SATURDAY_LC=$SATURDAY typeset -i day_of_week=-1 if [[ -n $day_of_weekStr ]]; then if [[ $day_of_weekStr == +([[:digit:]]) ]]; then if (( day_of_weekStr >= 0 && day_of_weekStr <= 6 )); then day_of_week=$day_of_weekStr else CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 "\nERROR: invalid value specified for \"%1\$s\": \"%2\$s\"\n\n" DAY_OF_WEEK "$day_of_weekStr" 1>&2 CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 "Valid values: %1\$s\n\n" "0, 1, 2, 3, 4, 5, 6" 1>&2 rc=$RC_INCORRECT_INPUT fi else typeset -l dow_lc=$day_of_weekStr case $dow_lc in $SUNDAY_LC) day_of_week=0 ;; $MONDAY_LC) day_of_week=1 ;; $TUESDAY_LC) day_of_week=2 ;; $WEDNESDAY_LC) day_of_week=3 ;; $THURSDAY_LC) day_of_week=4 ;; $FRIDAY_LC) day_of_week=5 ;; $SATURDAY_LC) day_of_week=6 ;; *) CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 "\nERROR: invalid value specified for \"%1\$s\": \"%2\$s\"\n\n" DAY_OF_WEEK "$day_of_weekStr" 1>&2 CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 "Valid values: %1\$s\n\n" "$SUNDAY, $MONDAY, $TUESDAY, $WEDNESDAY, $THURSDAY, $FRIDAY, $SATURDAY" 1>&2 rc=$RC_INCORRECT_INPUT ;; esac fi fi typeset NEVER=$(/usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 44 "Never") typeset DAILY=$(/usr/bin/dspmsg -s 36 cluster.cat 25 "Daily") typeset WEEKLY=$(/usr/bin/dspmsg -s 36 cluster.cat 26 "Weekly") typeset MONTHLY=$(/usr/bin/dspmsg -s 36 cluster.cat 27 "Monthly") typeset YEARLY=$(/usr/bin/dspmsg -s 36 cluster.cat 28 "Yearly") typeset -l NEVER_LC=$NEVER typeset -l DAILY_LC=$DAILY typeset -l WEEKLY_LC=$WEEKLY typeset -l MONTHLY_LC=$MONTHLY typeset -l YEARLY_LC=$YEARLY if [[ -n $repeats ]]; then if [[ $repeats == +([[:digit:]]) ]]; then case $repeats in 0) repeats="never" ;; 1) repeats="daily" ;; 2) repeats="weekly" ;; 3) repeats="monthly" ;; 4) repeats="yearly" ;; *) CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 "\nERROR: invalid value specified for \"%1\$s\": \"%2\$s\"\n\n" REPEATS "$repeats" 1>&2 CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 "Valid values: %1\$s\n\n" "0, 1, 2, 3, 4" 1>&2 rc=$RC_INCORRECT_INPUT esac else typeset -l repeats_lc=$repeats case $repeats_lc in $NEVER_LC) repeats="never" ;; $DAILY_LC) repeats="daily" ;; $WEEKLY_LC) repeats="weekly" ;; $MONTHLY_LC) repeats="monthly" ;; $YEARLY_LC) repeats="yearly" ;; *) CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 "\nERROR: invalid value specified for \"%1\$s\": \"%2\$s\"\n\n" REPEATS "$repeats" 1>&2 CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 3 "Valid values: %1\$s\n\n" "$NEVER, $DAILY, $WEEKLY, $MONTHLY, $YEARLY" 1>&2 rc=$RC_INCORRECT_INPUT ;; esac fi fi #================================================================ : Assuming an object was specified, see if it is a known object #================================================================ if [[ $timer != *([[:space:]]) ]]; then CL=$LINENO KLIB_HACMP_is_known_fallback_timer "$timer" (( $? != RC_SUCCESS )) && rc=$RC_NOT_FOUND fi #================= : Validate input #================= if [[ -z $timer ]]; then /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 rc=$RC_MISSING_INPUT elif (( $rc == RC_NOT_FOUND )); then /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 "\nERROR: \"%1\$s\" does not appear to exist!\n\n" "$timer" 1>&2 /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 143 "Available Fallback Timers:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_fallback_timers available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" fi if [[ "$*" == *([[:space:]]) ]]; then /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 401 "\nERROR: no valid modifications were specified for \"%1\$s\".\n\n" "$timer" 1>&2 rc=$RC_MISSING_INPUT fi if [[ -n $hour && $hour != +([[:digit:]]) ]]; then /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 "\nERROR: invalid value specified for \"%1\$s\": \"%2\$s\".\n\n" HOUR "$hour" 1>&2 rc=$RC_INCORRECT_INPUT fi if [[ -n $minute && $minute != +([[:digit:]]) ]]; then /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 "\nERROR: invalid value specified for \"%1\$s\": \"%2\$s\".\n\n" MINUTE "$minute" 1>&2 rc=$RC_INCORRECT_INPUT fi if [[ -n $year && $year != +([[:digit:]]) ]]; then /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 "\nERROR: invalid value specified for \"%1\$s\": \"%2\$s\".\n\n" YEAR "$year" 1>&2 rc=$RC_INCORRECT_INPUT fi if [[ -n $day_of_month && $day_of_month != +([[:digit:]]) ]]; then /usr/bin/dspmsg -s $CLMGR_SET $CLMGR_MSGS 110 "\nERROR: invalid value specified for \"%1\$s\": \"%2\$s\".\n\n" DAY_OF_MONTH "$day_of_month" 1>&2 rc=$RC_INCORRECT_INPUT fi #================================================================== : Modify the fallback timer if no input errors have been detected #================================================================== if (( $rc == RC_UNKNOWN )); then CL=$LINENO KLIB_HACMP_get_fallback_timer_attributes "$timer" timer_attrs [[ -z $repeats ]] && repeats=${timer_attrs[REPEATS]} if [[ $repeats == "never" ]]; then [[ -z $year ]] && year=${timer_attrs[YEAR]} [[ -z $month ]] && month=${timer_attrs[MONTH]} [[ -z $day_of_month ]] && day_of_month=${timer_attrs[DAY_OF_MONTH]} [[ -z $hour ]] && hour=${timer_attrs[HOUR]} [[ -z $minute ]] && minute=${timer_attrs[MINUTE]} if [[ -z $year ]] || (( year < 0 )); then CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 418 "\nERROR: to modify this timer to make it run only one time, the \"%1\$s\" attribute must be specified.\n" YEAR 1>&2 rc=$RC_MISSING_INPUT fi if [[ -z $month ]] || (( month < 0 )); then CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 419 "\nERROR: to modify this timer to make it repeat yearly, the \"%1\$s\" attribute must be specified.\n" MONTH 1>&2 rc=$RC_MISSING_INPUT fi if [[ -z $day_of_month ]] || (( day_of_month < 0 )); then CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 420 "\nERROR: to modify this timer to make it repeat monthly, the \"%1\$s\" attribute must be specified.\n" DAY_OF_MONTH 1>&2 rc=$RC_MISSING_INPUT fi if (( $rc == RC_UNKNOWN )); then print "$0()[$LINENO]($SECONDS): $HAUTILS/cltimerpolicy -a update -r once -n $timer -y $year -m $month -d $day_of_month -h $hour -M $minute" >>$CLMGR_TMPLOG # Always log commands $HAUTILS/cltimerpolicy -a update \ -r once \ -n $timer \ -y $year \ -m $month \ -d $day_of_month \ -h $hour \ -M $minute fi elif [[ $repeats == "yearly" ]]; then [[ -z $month ]] && month=${timer_attrs[MONTH]} [[ -z $day_of_month ]] && day_of_month=${timer_attrs[DAY_OF_MONTH]} [[ -z $hour ]] && hour=${timer_attrs[HOUR]} [[ -z $minute ]] && minute=${timer_attrs[MINUTE]} if [[ -z $month ]] || (( month < 0 )); then CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 419 "\nERROR: to modify this timer to make it repeat yearly, the \"%1\$s\" attribute must be specified.\n" MONTH 1>&2 rc=$RC_MISSING_INPUT fi if [[ -z $day_of_month ]] || (( day_of_month < 0 )); then CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 420 "\nERROR: to modify this timer to make it repeat monthly, the \"%1\$s\" attribute must be specified.\n" DAY_OF_MONTH 1>&2 rc=$RC_MISSING_INPUT fi if (( $rc == RC_UNKNOWN )); then print "$0()[$LINENO]($SECONDS): $HAUTILS/cltimerpolicy -a update -r yearly -n $timer -m $month -d $day_of_month -h $hour -M $minute" >>$CLMGR_TMPLOG # Always log commands $HAUTILS/cltimerpolicy -a update \ -r yearly \ -n $timer \ -m $month \ -d $day_of_month \ -h $hour \ -M $minute fi elif [[ $repeats == "monthly" ]]; then [[ -z $day_of_month ]] && day_of_month=${timer_attrs[DAY_OF_MONTH]} [[ -z $hour ]] && hour=${timer_attrs[HOUR]} [[ -z $minute ]] && minute=${timer_attrs[MINUTE]} if [[ -z $day_of_month ]] || (( day_of_month < 0 )); then CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 420 "\nERROR: to modify this timer to make it repeat monthly, the \"%1\$s\" attribute must be specified.\n" DAY_OF_MONTH 1>&2 rc=$RC_MISSING_INPUT fi if (( $rc == RC_UNKNOWN )); then print "$0()[$LINENO]($SECONDS): $HAUTILS/cltimerpolicy -a update -r monthly -n $timer -d $day_of_month -h $hour -M $minute" >>$CLMGR_TMPLOG # Always log commands $HAUTILS/cltimerpolicy -a update \ -r monthly \ -n $timer \ -d $day_of_month \ -h $hour \ -M $minute fi elif [[ $repeats == "weekly" ]]; then [[ -z $day_of_week ]] && day_of_week=${timer_attrs[DAY_OF_WEEK]} [[ -z $hour ]] && hour=${timer_attrs[HOUR]} [[ -z $minute ]] && minute=${timer_attrs[MINUTE]} if [[ -z $day_of_week ]] || (( day_of_week < 0 )); then CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 421 "\nERROR: to modify this timer to make it repeat weekly, the \"%1\$s\" attribute must be specified.\n" DAY_OF_WEEK 1>&2 rc=$RC_MISSING_INPUT fi if (( $rc == RC_UNKNOWN )); then print "$0()[$LINENO]($SECONDS): $HAUTILS/cltimerpolicy -a update -r weekly -n $timer -w $day_of_week -h $hour -M $minute" >>$CLMGR_TMPLOG # Always log commands $HAUTILS/cltimerpolicy -a update \ -r weekly \ -n $timer \ -w $day_of_week \ -h $hour \ -M $minute fi elif [[ $repeats == "daily" ]]; then [[ -z $hour ]] && hour=${timer_attrs[HOUR]} [[ -z $minute ]] && minute=${timer_attrs[MINUTE]} print "$0()[$LINENO]($SECONDS): $HAUTILS/cltimerpolicy -a update -r daily -n $timer -h $hour -M $minute" >>$CLMGR_TMPLOG # Always log commands $HAUTILS/cltimerpolicy -a update \ -r daily \ -n $timer \ -h $hour \ -M $minute fi typeset -i oprc=$? print "cltimerpolicy RC: $oprc" >>$CLMGR_TMPLOG # Always log command result if (( $rc == RC_UNKNOWN )); then (( $oprc == RC_SUCCESS )) && rc=$RC_SUCCESS || rc=$RC_ERROR else print -u2 "" fi fi #=========================================================== : If output from this operation was requested, retrieve it #=========================================================== if (( $rc == RC_SUCCESS )); then if (( CLMGR_VERBOSE )) || [[ -n $CLMGR_ATTRS ]]; then CL=$LINENO KLIB_HACMP_get_fallback_timer_attributes "$timer" properties fi fi #======================================================================= : If a user input error was detected, provide some helpful suggestions #======================================================================= if (( $rc == RC_MISSING_INPUT || $rc == RC_INCORRECT_INPUT )) && \ [[ $CLMGR_GUI == *([[:space:]]) ]] then CL=$LINENO cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 104 "For more information about available options and syntax, try\n\"$HAUTILS/clmgr %1\$s\". As an\nalternative, if the PowerHA SystemMirror man pages have been installed, invoke\n\"$HAUTILS/clmgr -hv\" (or \"/usr/bin/man clmgr\"),\nsearching for \"%2\$s\" in the displayed text.\n\n" \ "modify fallback_timer -h" "FALLBACK TIMER:" "$CLMGR_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_modify_fallback_timer()"