[sh]每天推送本地日志到log服务器

 

 


#vim /u1/scp_all_logs.sh

#!/bin/bash
#每天推送本地日志到log服务器
DATE=`date -d "yesterday" +%F`
logname=SSC_log_$DATE
ip=(`ifconfig|grep "inet addr"|grep -v "127.0.0.1" |awk '{print $2}'|awk -F: '{print $2}'`)
bakpath=/home/log_bakup/$ip
if test ! -d $bakpath;then
mkdir -p $bakpath
fi
cd /var/www/logs
tar -zcf $bakpath/log_$DATE.tar.gz *$DATE.log
sleep 5
expect -c "
set timeout 100
spawn /usr/bin/scp -r $bakpath [email protected]:/var/www/html/ip_logs
expect "*password*" 
send "'123456'\\r"
expect eof;"

rm  $bakpath/log_$DATE.tar.gz

exit 0

 

 

 

你可能感兴趣的:(服务器)