当前位置: 技术问答>linux和unix
哪位大虾能帮忙将下面的sh程序写下注释啊,谢谢!
来源: 互联网 发布时间:2016-01-26
本文导语: 哪位大虾能帮忙将下面的sh程序写下注释啊,谢谢! #!/bin/sh SH_DIR=/u1/tmn/etc export SH_DIR DEL_PATH=/u1/tmn/bin/alcol/hw_omc/log export DEL_PATH . $SH_DIR/crontab.env DT=`date "+%m%d"` DA=`date "+%d"` if [ "$DT" -eq "0101" ] then CUR_YEAR=`date "+%y"...
哪位大虾能帮忙将下面的sh程序写下注释啊,谢谢!
#!/bin/sh
SH_DIR=/u1/tmn/etc
export SH_DIR
DEL_PATH=/u1/tmn/bin/alcol/hw_omc/log
export DEL_PATH
. $SH_DIR/crontab.env
DT=`date "+%m%d"`
DA=`date "+%d"`
if [ "$DT" -eq "0101" ]
then
CUR_YEAR=`date "+%y"`
DEL_YEAR=`expr $CUR_YEAR - 1`
DEL_DATE=`date "+200"$DEL_YEAR"1231"`
else
if [ "$DA" -eq "01" ]
then
CUR_MON=`date "+%m"`
case $CUR_MON in
02,04,06,08,09 ) DEL_MON=`expr $CUR_MON - 1`
DEL_DATE=`date "+20%y"$DEL_MON"31"`
;;
11 ) DEL_MON=`expr $CUR_MON - 1`
DEL_DATE=`date "+20%y"$DEL_MON"31"`
;;
05,07,10 ) DEL_MON=`expr $CUR_MON - 1`
DEL_DATE=`date "+20%y"$DEL_MON"30"`
;;
12 ) DEL_MON=`expr $CUR_MON - 1`
DEL_DATE=`date "+20%y"$DEL_MON"30"`
;;
03 ) COU_YEAR=`date "+20%y"`
COU_MOD=`expr $COU_YEAR % 4`
if [ "$COU_MOD" -eq "0" ]
then
DEL_DATE=`date "+20%y0229"`
else
if [ "$COU_MOD" -ne "0" ]
then
DEL_DATE=`date "+20%y0228"`
fi
fi
esac
else
if [ "$DA" -lt "11" ]
then
DEL_DAY=`expr $DA - 1`
DEL_DATE=`date "+20%y%m0"$DEL_DAY""`
else
if [ "$DA" -gt "10" ]
then
DEL_DAY=`expr $DA - 1`
DEL_DATE=`date "+20%y%m"$DEL_DAY""`
fi
fi
fi
fi
rm $DEL_PATH/HWOMC*."$DEL_DATE"*
#!/bin/sh
SH_DIR=/u1/tmn/etc
export SH_DIR
DEL_PATH=/u1/tmn/bin/alcol/hw_omc/log
export DEL_PATH
. $SH_DIR/crontab.env
DT=`date "+%m%d"`
DA=`date "+%d"`
if [ "$DT" -eq "0101" ]
then
CUR_YEAR=`date "+%y"`
DEL_YEAR=`expr $CUR_YEAR - 1`
DEL_DATE=`date "+200"$DEL_YEAR"1231"`
else
if [ "$DA" -eq "01" ]
then
CUR_MON=`date "+%m"`
case $CUR_MON in
02,04,06,08,09 ) DEL_MON=`expr $CUR_MON - 1`
DEL_DATE=`date "+20%y"$DEL_MON"31"`
;;
11 ) DEL_MON=`expr $CUR_MON - 1`
DEL_DATE=`date "+20%y"$DEL_MON"31"`
;;
05,07,10 ) DEL_MON=`expr $CUR_MON - 1`
DEL_DATE=`date "+20%y"$DEL_MON"30"`
;;
12 ) DEL_MON=`expr $CUR_MON - 1`
DEL_DATE=`date "+20%y"$DEL_MON"30"`
;;
03 ) COU_YEAR=`date "+20%y"`
COU_MOD=`expr $COU_YEAR % 4`
if [ "$COU_MOD" -eq "0" ]
then
DEL_DATE=`date "+20%y0229"`
else
if [ "$COU_MOD" -ne "0" ]
then
DEL_DATE=`date "+20%y0228"`
fi
fi
esac
else
if [ "$DA" -lt "11" ]
then
DEL_DAY=`expr $DA - 1`
DEL_DATE=`date "+20%y%m0"$DEL_DAY""`
else
if [ "$DA" -gt "10" ]
then
DEL_DAY=`expr $DA - 1`
DEL_DATE=`date "+20%y%m"$DEL_DAY""`
fi
fi
fi
fi
rm $DEL_PATH/HWOMC*."$DEL_DATE"*
|
就是找到当前日期的前一天,删除指定那个日期命名的文件。
那么多if,else,case什么的都是废话,一个date命令就可以得到当前日期的前一天。
那么多if,else,case什么的都是废话,一个date命令就可以得到当前日期的前一天。
|
没有测试,你的sh脚本大概可以改写成这个样子:
#!/bin/sh
SH_DIR=/u1/tmn/etc
export SH_DIR
DEL_PATH=/u1/tmn/bin/alcol/hw_omc/log
export DEL_PATH
. $SH_DIR/crontab.env
DEL_DATE=`date -d "-1 day" +%Y%m%d`
rm $DEL_PATH/HWOMC*."$DEL_DATE"*
linux通用。
#!/bin/sh
SH_DIR=/u1/tmn/etc
export SH_DIR
DEL_PATH=/u1/tmn/bin/alcol/hw_omc/log
export DEL_PATH
. $SH_DIR/crontab.env
DEL_DATE=`date -d "-1 day" +%Y%m%d`
rm $DEL_PATH/HWOMC*."$DEL_DATE"*
linux通用。