2011年(5)
分类: LINUX
2011-09-12 15:03:35
#!/bin/ksh
echo ""
echo "##############################################################################"
echo ""
echo "开始处理 ${1} "
echo "Start Time is `date`"
echo ""
####################################################################################
#######
####### 检查Parameters
#######
####################################################################################
echo "--------------------------------"
echo ""
echo "1. Parameters检查"
echo ""
MONTH=`echo $1 | cut -c 1-2`
DAY=`echo $1 | cut -c 3-4`
P=$#
case $P in
"1")
if [[ ${MONTH} = 0[1-9] || ${MONTH} = 1[0-2] ]]
then
DO_MONTH=${MONTH}
else
echo "****** Warning ******"
echo ""
echo "您输入的月份不正确"
echo "请输入正确的月份"
echo ""
exit 3
fi
DO_YEAR=`date +%Y`
;;
"2")
if [[ ${MONTH} = 0[1-9] || ${MONTH} = 1[0-2] ]]
then
DO_MONTH=${MONTH}
else
echo "****** Warning ******"
echo ""
echo "$1 为不正确的数值"
echo "请输入正确的月份"
echo ""
exit 3
fi
if [[ $2 = 2[0-9][0-9][0-9] || $2 = 199[0-9] ]]
then
DO_YEAR=$2
else
echo "****** Warning ******"
echo ""
echo "$2为不正确的数值"
echo "在『1990~2999』范围内输入你想要输入的年份"
echo ""
exit 3
fi
;;
*)
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters"
echo "P1 (执行的月和日) P2 (执行的年份) 不指定第二个年份的时候,按照执行日的年份来计算"
echo ""
exit 3
;;
esac
case ${DO_MONTH} in
"01")
if [[ ${DAY} -lt 01 || ${DAY} -gt 31 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters "
echo "P1 (执行的月和日)不正确。"
echo "在『01~31』范围内输入"
echo ""
exit 3
fi
;;
"02")
RTN_YEAR=$DO_YEAR
RTN_YEAR=`expr $RTN_YEAR + 0`
CHK_YEAR_4=`expr $RTN_YEAR % 4`
CHK_YEAR_100=`expr $RTN_YEAR % 100`
CHK_YEAR_400=`expr $RTN_YEAR % 400`
if [ $CHK_YEAR_400 -eq 0 -o $CHK_YEAR_4 -eq 0 -a $CHK_YEAR_100 -ne 0 ]
then
if [[ ${DAY} -lt 01 || ${DAY} -gt 29 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters "
echo " P1 (执行的月和日)不正确。"
echo "在『01~29』范围内输入"
echo ""
exit 3
fi
else
if [[ ${DAY} -lt 01 || ${DAY} -gt 28 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters "
echo " P1 (执行的月和日)不正确。"
echo "在『01~28』范围内输入"
echo ""
exit 3
fi
fi
;;
"03")
if [[ ${DAY} -lt 01 || ${DAY} -gt 31 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters "
echo " P1 (执行的月和日)不正确。"
echo "在『01~31』范围内输入"
echo ""
exit 3
fi
;;
"04")
if [[ ${DAY} -lt 01 || ${DAY} -gt 30 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters!"
echo " P1 (执行的月和日)不正确。"
echo "在『01~30』范围内输入"
echo ""
exit 3
fi
;;
"05")
if [[ ${DAY} -lt 01 || ${DAY} -gt 31 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters!"
echo " P1 (执行的月和日)不正确。"
echo "在『01~31』范围内输入"
echo ""
exit 3
fi
;;
"06")
if [[ ${DAY} -lt 01 || ${DAY} -gt 30 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters!"
echo " P1 (执行的月和日)不正确。。"
echo "在『01~30』范围内输入"
echo ""
exit 3
fi
;;
"07")
if [[ ${DAY} -lt 01 || ${DAY} -gt 31 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters!"
echo " P1 (执行的月和日)不正确。。"
echo "『在『01~31』范围内输入"
echo ""
exit 3
fi
;;
"08")
if [[ ${DAY} -lt 01 || ${DAY} -gt 31 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters!"
echo " P1 (执行的月和日)不正确。。"
echo "在『01~31』范围内输入"
echo ""
exit 3
fi
;;
"09")
if [[ ${DAY} -lt 01 || ${DAY} -gt 30 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters!"
echo " P1 (执行的月和日)不正确。。"
echo "在『01~30』范围内输入"
echo ""
exit 3
fi
;;
"10")
if [[ ${DAY} -lt 01 || ${DAY} -gt 31 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters!"
echo " P1 (执行的月和日)不正确。。"
echo "在『01~31』范围内输入"
echo ""
exit 3
fi
;;
"11")
if [[ ${DAY} -lt 01 || ${DAY} -gt 30 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters!"
echo " P1 (执行的月和日)不正确。。"
echo "在『01~30』范围内输入"
echo ""
exit 3
fi
;;
"12")
if [[ ${DAY} -lt 01 || ${DAY} -gt 31 ]]
then
echo "****** Warning ******:"
echo ""
echo "请检查您的Parameters!"
echo " P1 (执行的月和日)不正确。。"
echo "在『01~31』范围内输入"
echo ""
exit 3
fi
;;
esac
echo "Parameters检查结束"
echo ""