前端之家收集整理的这篇文章主要介绍了
Shell-实际业务操作03,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/bin/sh
EXIT_FAILURE=1
EXIT_SUCCESS=0
BEGIN_TIME=`date +%s`
SCRIPT_PATH=$(cd `dirname $0`; pwd)
SCRIPT_NAME=`basename $0`
LOG_LOCATION=/ocs/tools/OperCDR/logs
VOICE_NORMAL=/bakcdr/cdrbak/VOICE/normal
VOICE_GZ_FILE=/bakcdr/cdrbak/VOICE/gz_file
DATA_NORMAL=/bakcdr/cdrbak/DATA/normal
DATA_GZ_FILE=/bakcdr/cdrbak/DATA/gz_file
SMS_NORMAL=/bakcdr/cdrbak/SMS/normal
SMS_GZ_FILE=/bakcdr/cdrbak/SMS/gz_file
HOST="172.25.243.151"
USER="cdr"
PASSWD="cdr"
REMOTE_DATA_PATH=/backup_storage/bakcdr_ocs/DATA
REMOTE_VOICE_PATH=/backup_storage/bakcdr_ocs/VOICE
REMOTE_SMS_PATH=/backup_storage/bakcdr_ocs/SMS
TarCDRMenu2GZ(){
if [ -d $1 ] ; then
cd $1
for dateMenu in `ls`
do
echo 目录名称 $dateMenu
if [ -d $1/$dateMenu ] ; then
tar -zcvf $dateMenu.tar.gz $dateMenu
if [ $? == 0 ] ; then
echo "$1/$dateMenu.tar.gz tared successfully " >>$LOG_LOCATION/TarCdrAndTransfer.log 2>&1
mv $dateMenu.tar.gz $2
echo "$1/$dateMenu.tar.gz to $2 successfully " >>$LOG_LOCATION/TarCdrAndTransfer.log 2>&1
fi
else
echo -e "\033[31m ERROR $1/$dateMenu is not a directory \033[0m" >>$LOG_LOCATION/TarCdrAndTransfer.log 2>&1
fi
done
else
echo -e "\033[31m ERROR $1 does not exist \033[0m" >>$LOG_LOCATION/TarCdrAndTransfer.log 2>&1
fi
}
FtpFile(){
echo FtpFile $1 >>$LOG_LOCATION/TarCdrAndTransfer.log 2>&1
for file in `ls $1`
do
if [[ $1 =~ "DATA" ]] ; then
PutDataFileByFtp $1 $file
echo "$1/$file put to remote server $HOST $REMOTE_DATA_PATH successfully " >>$LOG_LOCATION/TarCdrAndTransfer.log 2>&1
elif [[ $1 =~ "VOICE" ]] ; then
PutVoiceFileByFtp $1 $file
echo "$1/$file put to remote server $HOST $REMOTE_VOICE_PATH successfully " >>$LOG_LOCATION/TarCdrAndTransfer.log 2>&1
else
PutSmsFileByFtp $1 $file
echo "$1/$file put to remote server $HOST $REMOTE_SMS_PATH successfully " >>$LOG_LOCATION/TarCdrAndTransfer.log 2>&1
fi
done
}
PutDataFileByFtp(){
ftp -i -n $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
cd $REMOTE_DATA_PATH
put $1/$2 $2
quit
EOF
}
PutVoiceFileByFtp(){
ftp -i -n -d $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
cd $REMOTE_VOICE_PATH
put $1/$2 $2
quit
EOF
}
PutSmsFileByFtp(){
ftp -i -n -d $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
cd $REMOTE_SMS_PATH
put $1/$2 $2
quit
EOF
}
echo "==========================begin `date "+%Y-%m-%d %H:%M:%S"`===============================================" >>$LOG_LOCATION/TarCdrAndTransfer.log 2>&1
TarCDRMenu2GZ $DATA_NORMAL $DATA_GZ_FILE
TarCDRMenu2GZ $VOICE_NORMAL $VOICE_GZ_FILE
TarCDRMenu2GZ $SMS_NORMAL $SMS_GZ_FILE
FtpFile $DATA_GZ_FILE
FtpFile $SMS_GZ_FILE
FtpFile $VOICE_GZ_FILE
END_TIME=$(date +%s)
echo "==========================end `date "+%Y-%m-%d %H:%M:%S"`=================================================" >>$LOG_LOCATION/TarCdrAndTransfer.log 2>&1
echo "==========================time consuming $(($END_TIME - $BEGIN_TIME)) seconds=================================================" >>$LOG_LOCATION/TarCdrAndTransfer.log 2>&1
echo "" >>$LOG_LOCATION/TarCdrAndTransfer.log 2>&1
exit $EXIT_SUCCESS