solaris中sheel得到历史时间
下面这段脚本:
monthago=4 表示想要得到4个月以前的时间。
${deleteyear}是4个月以前的年份
${deletemonth}是4个月以前的月份。
比如现在是的时间是201005,那么${deleteyear}=2010,${deletemonth}=01
比如现在是的时间是201004,那么${deleteyear}=2009,${deletemonth}=12
?
#!/usr/bin/bash
monthago=4
monthsum=`expr 12 + ${monthago}`
myyear=`date +%Y`
mymonth=`date +%m`
tmp=`expr ${mymonth} + 12`
if(test ${tmp} -le ${monthsum})
? then
??? deletemonth=`expr ${tmp} - ${monthago}`
??? deleteyear=`expr ${myyear} - 1`
? else
??? deletemonth=`expr ${mymonth} - ${monthago}`
??? deleteyear=`expr ${myyear}`
fi
if(test ${deletemonth} -lt 10)
? then
??? deletemonth="0"${deletemonth}
fi
rm -rf /export/home/backup/${deleteyear}${deletemonth}*