UNIX/Linux 脚本和说明

通过复制本节中的脚本,创建 input.propertiesskip_update.sh

  1. 通过复制以下脚本来创建 input.properties
    javahome=JAVA_HOME
    epmautomatescript=EPM_AUTOMATE_LOCATION
    username=exampleAdmin
    password=examplePassword.epw
    url=exampleURL
    updatemonths=02,05,08,11
    
  2. 通过指定参数值更新 input.properties

    Table 3-12 input.properties 参数

    参数 说明
    javahome JAVA_HOME 位置。
    epmautomatescript EPM Automate 可执行文件 (epmautomate.sh) 的绝对路径。
    username 服务管理员的用户名。
    password 服务管理员的密码或加密密码文件的名称和位置。
    url 更新节奏要设置为不是每月一次的环境的 URL。
    updatemonths 应将 Oracle Enterprise Performance Management Cloud 更新应用于 url 参数所标识环境的月份的逗号分隔列表。例如,updatemonths=02,05,08,11

    月份必须指定为两位数字;一月到九月的数字包含前面的零。该脚本尝试为没有包含在 updatemonths 参数值中的月份运行 skipUpdate 命令。例如,如果指定 updatemonths=02,05,08,11,则脚本尝试为一月、三月、四月、六月、七月、九月、十月和十二月设置跳过更新标志,以便更新仅在二月、五月、八月和十一月进行。

  3. 通过复制以下脚本来创建 skip_updates.sh
    #!/bin/sh
    
    . ./input.properties
    export JAVA_HOME=${javahome}
    
    declare -a monthsarr=(01 02 03 04 05 06 07 08 09 10 11 12)
    declare -a monthsarrfromcurrent
    declare -a yearsarrfromcurrent
    updatemonthsarr=( $(echo "${updatemonths}" | sed 's/,/ /g') ) 
    currentyear=$(date +%y)
    nextyear=$((currentyear+1))
    currentmonth=$(date +%m)
    
    populateFromCurrentArrays() {
        for i in ${!monthsarr[@]}
        do
            if [[ "${currentmonth}" == "${monthsarr[$i]}" ]]
            then 
                startposition=$i
                break
            fi
        done
    
        for i in ${!monthsarr[@]}
        do
            if [[ ${i} -ge ${startposition} ]]
            then 
                monthsarrfromcurrent=("${monthsarrfromcurrent[@]}" "${monthsarr[$i]}")
                yearsarrfromcurrent=("${yearsarrfromcurrent[@]}" "${currentyear}")
            fi
        done
    
        for i in ${!monthsarr[@]}
        do
            if [[ ${i} -lt ${startposition} ]]
            then 
                monthsarrfromcurrent=("${monthsarrfromcurrent[@]}" "${monthsarr[$i]}")
                yearsarrfromcurrent=("${yearsarrfromcurrent[@]}" "${nextyear}")
            fi
        done
    }
    
    skipUpdateAdd() {
        local yearnumber="$1"
        local monthnumber="$2"
    
        echo "Running: ${epmautomatescript} skipUpdate add version=${yearnumber}.${monthnumber} comment=\"adding skipUpdate\""
        ${epmautomatescript} skipUpdate add version=${yearnumber}.${monthnumber} comment="adding skipUpdate"
    }
    
    processSkipUpdates() {
        local addcount=0
    
        echo "Running: ${epmautomatescript} login ${username} ${password} ${url}"
        ${epmautomatescript} login ${username} ${password} ${url}
        echo "Running: ${epmautomatescript} skipUpdate remove"
        ${epmautomatescript} skipUpdate remove
    
        for i in ${!monthsarrfromcurrent[@]}
        do
            local match=1
    
            if [[ ${addcount} -eq 2 ]]
            then
                echo "Two skip update add calls have been made. No more will be attempted."
                break
            fi
    
            for j in ${!updatemonthsarr[@]}
            do
                if [[ "${monthsarrfromcurrent[$i]}" == "${updatemonthsarr[$j]}" ]]
                then
                    match=0
                    break
                fi
            done
    
            if [[ ${match} -eq 1 ]]
            then 
                skipUpdateAdd ${yearsarrfromcurrent[$i]} "${monthsarrfromcurrent[$i]}"
                addcount=$((addcount+1))
            fi
        done
    
        echo "Running: ${epmautomatescript} skipUpdate list"
        ${epmautomatescript} skipUpdate list
        echo "Running: ${epmautomatescript} logout"
        ${epmautomatescript} logout
    }
    
    compareUpdateMonths() {
        local thismonth=$1
        local nextmonth=$2
        local nextmonthorig=${nextmonth}
     
        if [[ ${nextmonth} -lt ${thismonth} ]]
        then
            nextmonth=$((nextmonth+12))
        fi
    
        monthdiff=$((nextmonth-thismonth))
    
        if [[ ${monthdiff} -gt 3 ]]
        then 
            echo "There are more than 2 months skipped from month ${thismonth} to month ${nextmonthorig}. Please correct updatemonths in input.properties so that there are not more than two months skipped between each update month. Exiting."
            exit 1
        fi
    }
    
    validateUpdateMonths() {
        for i in ${!updatemonthsarr[@]}
        do
            nextint=$((i+1))
            thisupdatemonth="${updatemonthsarr[$i]}"
            thisupdatemonthint=${thisupdatemonth#0}
            nextupdatemonth="${updatemonthsarr[$nextint]}"
            nextupdatemonthint=${nextupdatemonth#0}
    
            if [[ ${nextupdatemonth} == "" ]]
            then 
                nextupdatemonth="${updatemonthsarr[0]}"
                nextupdatemonthint=${nextupdatemonth#0}
            fi
    
            compareUpdateMonths ${thisupdatemonthint} ${nextupdatemonthint}
        done
    }
    
    validateUpdateMonths
    populateFromCurrentArrays
    processSkipUpdates