先月のログのバックアップ
2200 ワード
. ~/.bash_profile
#
CLEAR_PATH="/usr/local/apache-tomcat-7.0.55_8081/logs"
cd $CLEAR_PATH
LMONTH=`date -d "-1 month" +%m`
YEAR=`date +%Y`
if [ "$LMONTH" -eq "12" ]
then
YEAR=`expr $YEAR - 1`
fi
date_trans()
{
if test "$LMONTH" = "01" ;then
LMONTH=Jan
elif [ "$LMONTH" = "02" ];then
LMONTH=Feb
elif [ "$LMONTH" = "03" ];then
LMONTH=Mar
elif [ "$LMONTH" = "04" ];then
LMONTH=Apr
elif [ "$LMONTH" = "05" ];then
LMONTH=May
elif [ "$LMONTH" = "06" ];then
LMONTH=Jun
elif [ "$LMONTH" = "07" ];then
LMONTH=Jul
elif [ "$LMONTH" = "08" ];then
LMONTH=Aug
elif [ "$LMONTH" = "09" ];then
LMONTH=Sep
elif [ "$LMONTH" = "10" ];then
LMONTH=Oct
elif [ "$LMONTH" = "11" ];then
LMONTH=Nov
elif [ "$LMONTH" = "12" ];then
LMONTH=Dec
fi
}
date_trans
echo $YEAR
echo $LMONTH
ls -lt | awk 'BEGIN{print "'"$LMONTH"'"}{if ($6~/'$LMONTH'/) print $0}' | awk '{if ($9~/log/) print $9}' >file.txt
if [ -s "file.txt" ]
then
sed -n 's/^/& rm -f /p' file.txt >rmlog.sh
sed '1s/^/&tar -czvf flow-x.x.x.x.$YEAR$LMONTH.tar.gz /' file.txt >.1
# \
sed 's/$/& \\/' .1 | sed '$s/\\//' > .2
sed '1 i \fi' .2 | sed '1 i \YEAR=`expr $YEAR - 1`' | sed '1 i \then' | sed '1 i \if [ "$LMONTH" -eq "12" ]' >.3
sed '1 i \YEAR=`date '+%Y'`' .3 > .4
sed '1 i \LMONTH=`date -d "-1 month" +%m`' .4 > .5
sed '1 i \cd $CLEAR_PATH' .5 > .6
sed '1 i \CLEAR_PATH="/usr/local/apache-tomcat-7.0.55_8081/logs"' .6 > tar.sh
cd /usr/local/apache-tomcat-7.0.55_8081/logs
sh ./tar.sh
sh ./rmlog.sh
LMONTH=`date -d "-1 month" +%m`
###FTP
ftp -n<<!
open x.x.x.x
user scan xxxx
pass
bin
put flow-x.x.x.x.$YEAR$LMONTH.tar.gz
exit
!
else
echo " "
fi