Hi Folks -
Linux Version = Linux 2.6.39-400.128.17.el5uek x86_64
I have a process that determines the start and end load periods for an Oracle data load process.
The variables used are as follows follows:
They are populated like such:
However, the load requires the month to be the 3 digit format rather than number format. Therefore, to get around it, I am using a cut methodology but I w wondering if I'm over complicating things and there is an easier way?
GetLoadPOVValues () {
#::-- Usage --::#
# Param 1 = Required Year digits [i.e. 2 or 4]
# Param 2 = Number of periods to load [i.e. YTD or 1 or 2 etc]
# Examples are based on a November 2018 run-time
# Example = GetLoadPOVValues "2" "1" says use 2 digit year [18] and _STARTPOV & _ENDPOV are the same [Oct-2018] since loading only 1 month
# Example = GetLoadPOVValues "4" "YTD" says use 4 digit year [2018] and _STARTPOV is Jan-2018 and _ENDPOV is Oct-2018
_REGEXP='^[0-9]+$'
_DIGIT="$1"; [ "${_DIGIT}" -eq "2" ] && _YR="y" || _YR="Y"
_NUMPD="$2"
if ! [[ "${_NUMPD}" =~ "${_REGEXP}" ]]
then
_STARTPOV="1-$(date +%${_YR})"
else
_STARTPOV=`date -d "$(date +%Y-%m-1) -${_NUMPD} month" +%-m-%${_YR}`
fi
_ENDPOV=`date -d "$(date +%Y-%m-1) -1 month" +%-m-%${_YR}`
_M="$( cut -d '-' -f 1 <<< "$_ENDPOV" )"; GetMonth "${_M}"; _YR="$( cut -d '-' -f 2 <<< "$_ENDPOV" )"; _ENDPOV="${_M}-${_YR}"
_M="$( cut -d '-' -f 1 <<< "$_STARTPOV" )"; GetMonth "${_M}"; _YR="$( cut -d '-' -f 2 <<< "$_STARTPOV" )"; _STARTPOV="${_M}-${_YR}"
}
GetMonth () {
_NUM="$1"
[[ "${_NUM}" == "01" ]] && _M="Jan" || [[ "${_NUM}" == "1" ]] && _M="Jan"
[[ "${_NUM}" == "02" ]] && _M="Feb" || [[ "${_NUM}" == "2" ]] && _M="Feb"
[[ "${_NUM}" == "03" ]] && _M="Mar" || [[ "${_NUM}" == "3" ]] && _M="Mar"
[[ "${_NUM}" == "04" ]] && _M="Apr" || [[ "${_NUM}" == "4" ]] && _M="Apr"
[[ "${_NUM}" == "05" ]] && _M="May" || [[ "${_NUM}" == "5" ]] && _M="May"
[[ "${_NUM}" == "06" ]] && _M="Jun" || [[ "${_NUM}" == "6" ]] && _M="Jun"
[[ "${_NUM}" == "07" ]] && _M="Jul" || [[ "${_NUM}" == "7" ]] && _M="Jul"
[[ "${_NUM}" == "08" ]] && _M="Aug" || [[ "${_NUM}" == "8" ]] && _M="Aug"
[[ "${_NUM}" == "09" ]] && _M="Sep" || [[ "${_NUM}" == "9" ]] && _M="Sep"
[[ "${_NUM}" == "10" ]] && _M="Oct"
[[ "${_NUM}" == "11" ]] && _M="Nov"
[[ "${_NUM}" == "12" ]] && _M="Dec"
}
GetLoadPOVValues "2" "2"
Thank you!!