new_logarchive.sh

#!/bin/bash
#mwg@2012-4-4
banben=jx2
qufu=101-4
gsnum=(1 2 3 4)
###################
if [ ${banben} = jx2 -o ${banben} = jx2ib ]
then
GSDIR=/home/xmission/jxonline2/gs
WORKDIR=/home/xmission/jxonline2/jx2tools/logarchive/
elif [ ${banben} = jx2wz ]
then
GSDIR=/home/kingsoft/server/gameserver0
WORKDIR=/home/kingsoft/server/jx2tools/logarchive/
else
echo "banben is error"
exit
fi
TAR_MONTH=`date -d "1 days ago" +%Y_%m`
PDIR5=/${banben}/$TAR_MONTH/Real-time_upload/new_Gameserver_${qufu}/
###################
LOCALLOGSAVEDIR=$WORKDIR'new_log-tar-save'
#FTP set
FTPU='xxxx'
FTPP='xxxx'
FTPH='0.0.0.0'
NCFTPPUT=$WORKDIR'ncftpput'
[ ! -d $LOCALLOGSAVEDIR/ ] &&  mkdir -p $LOCALLOGSAVEDIR/
for j in ${gsnum[@]}
do
        cd /home/xmission/jxonline2/jx2tools/logarchive/
        [ -d ./tmp/ ] || mkdir ./tmp/
#判断是否为首次执行
#不是首次执行
        if [ -f tmp/old_logfile$j ] && old_logfile=$(cat ./tmp/old_logfile$j) && [ -n $old_logfile ] && old_basefile=$(basename ${old_logfile})
        then
                line_num=$(ls -lt --time-style '+%Y-%m-%d %H:%M:%S' $GSDIR$j/logs/GameServer/*/* |cat -n|awk '{print $1,$9}'|grep "$old_basefile"|awk '{print $1}')
#判判断上次上传的文件是否在第二行
#是的话跳过
                if [ $line_num -eq 2 ]
                then
                        :
                else
#如果上次上传的文件所在位置大于2,则上传第2个文件到上次已上传文件
                        files=($(ls -lt --time-style '+%Y-%m-%d %H:%M:%S' $GSDIR$j/logs/GameServer/*/* |awk '{print $8}'|sed -n "2,/$old_basefile/p"|grep -v "$old_basefile"))
                        for i in ${files[@]}
                        do
                                basefile=$(basename ${i})
                                tar czf $LOCALLOGSAVEDIR/'GS'${j}_${basefile}.tar.gz  ${i}
                                $NCFTPPUT -u$FTPU -p$FTPP -m -R -DD $FTPH $PDIR5 $LOCALLOGSAVEDIR/'GS'${j}_${basefile}.tar.gz \
                                || $NCFTPPUT -u$FTPU -p$FTPP -m -R -DD $FTPH $PDIR5 $LOCALLOGSAVEDIR/'GS'${j}_${basefile}.tar.gz \
                                || $NCFTPPUT -u$FTPU -p$FTPP -m -R -DD $FTPH $PDIR5 $LOCALLOGSAVEDIR/'GS'${j}_${basefile}.tar.gz
                        done
                        old_logfile=${files[0]}
                        echo $old_logfile > ./tmp/old_logfile$j
                fi
#首次执行此脚本
        else
                file1=$(ls -lt --time-style '+%Y-%m-%d %H:%M:%S' $GSDIR$j/logs/GameServer/*/* |awk '{print $8}'|sed -n '2p')
                basefile=$(basename ${file1})
                tar czf $LOCALLOGSAVEDIR/'GS'${j}_${basefile}.tar.gz  ${file1}
                old_logfile=$file1
                echo $old_logfile > ./tmp/old_logfile$j
                $NCFTPPUT -u$FTPU -p$FTPP -m -R -DD $FTPH $PDIR5 $LOCALLOGSAVEDIR/'GS'${j}_${basefile}.tar.gz \
                || $NCFTPPUT -u$FTPU -p$FTPP -m -R -DD $FTPH $PDIR5 $LOCALLOGSAVEDIR/'GS'${j}_${basefile}.tar.gz \
                || $NCFTPPUT -u$FTPU -p$FTPP -m -R -DD $FTPH $PDIR5 $LOCALLOGSAVEDIR/'GS'${j}_${basefile}.tar.gz
        fi
done
exit 0


你可能感兴趣的:(server,error)