log上传

一、log提取更新说明:
从原来提取的dhcp和apache的log中有用的信息有限;根据要求,要从dhcp和apacha中提取更多用户访问设备的信息,具体如下:
dhcp提取更新:增加了终端的设备号,android设备号大致为:android-7231aba3bfaed03d
苹果设备为各个苹果设备设置的用户名,如果没有修改过的话为:ipad、iPod、iPhone等
格式如下:
Nov 22 11:00:14 192.168.1.104 98:e7:9a:08:c8:d8 (android-7231aba3bfaed03d)
Nov 22 11:23:47 192.168.1.134 18:46:17:23:2a:bf (ipod)
apache提取更新:增加了终端访问设备的详细的URL,精确到访问的每个文件链接以及该终端设备的系统信息,如系统、系统版本、浏览器信息等等
格式如下:
192.168.252.65 - - [23/Jan/2013:11:08:38 +0800] "GET /image/shuai02.jpg HTTP/1.1" 200 47865 "http://192.168.1.1/books.html" "Mozilla/5.0 (Linux; U; Android 2.2; zh-cn; HTCA8180/1.0 Android/2.2 release/06.23.2010 Browser/WAP 2.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
二、log提取配置说明: 
修改ADFI脚本中的:
cat /var/log/dhcpd.log | grep DHCPACK |awk '{print $1" "$2" "$3" "$8" "$10}' >> $dhcp_name
.
cat /var/log/apache2/access.log |awk '{print $1" "$4$5" "$8}' >> $apache_name
为:
cat /var/log/dhcpd.log | grep "DHCPACK on" |awk '{print $1" "$2" "$3" "$8" "$10" "$11}' >> $dhcp_name
.
cat /var/log/apache2/access.log | grep GET | sed '\/?p=verify/d' >> $apache_name
三、log上传更新说明:
修复由于3G网络不通导致log漏传的漏洞
修复log上传脚本后台运行占用不必要资源的漏洞
修复上传当天log而导致远程同名log被替换而导致的log丢失的漏洞
四、log上传配置说明:
1、将修改好的log上传脚本upload_log.sh脚本拷贝至/adfipro/logs/目录下
2、修改/etc/init.d/rc.local文件
在最后一行sh /etc/init.d/ADFI &后加上
sleep 60
sh /adfipro/logs/upload_log.sh &即可
修改后为:
sh /etc/init.d/ADFI &
sleep 60
sh /adfipro/logs/upload_log.sh &
 
 
 
#!/bin/sh
 
echo "`date "+%Y-%m-%d %H:%M:%S"` upload_log.sh is running!" > /adfipro/logs/ftp.log
 
#FTP服务器参数
ftphost="119.188.10.163"
username="adfi_ftp"
passwd="adfi1!"
 
cnt_upload=0
 
device_id=`cat /adfipro/device_id`
echo "`date "+%Y-%m-%d %H:%M:%S"` This Device ID is $device_id" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` -----------------------------------------------------------------------------------------------" >> /adfipro/logs/ftp.log
 
#需要备份文件的目录
filepath="/adfipro/logs"
 
#FTP Server备份目录
backupdir="/log/$device_id"
 
cd /adfipro/logs
 
rm -f /adfipro/logs/*tar.gz
 
while true
do
for log_files in apache.log* dhcp.log*
do
if [ -f $log_files ];then
if [ $log_files = apache.log.$device_id.`date +%Y-%m-%d` ]||[ $log_files = dhcp.log.$device_id.`date +%Y-%m-%d` ];then
#echo $log_files >> /adfipro/logs/today_files.log
echo "`date "+%Y-%m-%d %H:%M:%S"` The $log_files is today's log file,do not upload!" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` -----------------------------------------------------------------------------------------------" >> /adfipro/logs/ftp.log
else
state=0 #0 is ok;1 is failed
#state=$(cat /adfipro/3g.state) #0 is ok;1 is failed
if [ $state = 0 ];then
echo "`date "+%Y-%m-%d %H:%M:%S"` 3G_state=$state;3G is ok!" >> /adfipro/logs/ftp.log
des_files="$log_files.tar.gz"
tar -zcvf $des_files $log_files
res=$(ping 8.8.8.8 -c 3 | grep received | awk '{print $4}') #3 is ok; or is failed
if [ $res = 3 ];then
#echo $log_files
echo "`date "+%Y-%m-%d %H:%M:%S"` Res_ping=$res;Network is ok!" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` Begin use ftp to upload the $log_files file!" >> /adfipro/logs/ftp.log
 
#Begin use ftp to upload the log file!
ftp -n -i -v $ftphost << EOF
user $username $passwd
cd $backupdir
lcd $filepath
passive
binary
put $des_files
bye
EOF
 
echo "`date "+%Y-%m-%d %H:%M:%S"` $log_files is uploaded" >> /adfipro/logs/ftp.log
 
#Begin use ftp to download the log file attributes!
sleep 1
cnt_download=0
cnt_ping=0
sleep_time_download=0
while true
do
res=$(ping 8.8.8.8 -c 3 | grep received | awk '{print $4}') #3 is ok; or is failed
if [ $res = 3 ];then
echo "`date "+%Y-%m-%d %H:%M:%S"` Res_ping=$res;Network is ok!" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` Begin use ftp to download the $log_files file attributes!" >> /adfipro/logs/ftp.log
 
ftp -n -i -v $ftphost << EOF
user $username $passwd
cd $backupdir
lcd $filepath
passive
binary
dir $des_files tmp.log
bye
EOF
sleep 1
remote_file_size=`cat /adfipro/logs/tmp.log | awk '{print $5}'`
local_file_size=`ls -l /adfipro/logs/$des_files | awk '{print $5}'`
echo "`date "+%Y-%m-%d %H:%M:%S"` remote_file_size=$remote_file_size" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` local_file_size=$local_file_size" >> /adfipro/logs/ftp.log
rm -f /adfipro/logs/tmp.log
 
if [ $remote_file_size = $local_file_size ];then
 
echo "`date "+%Y-%m-%d %H:%M:%S"` $log_files is upload completely! Break! Then begin to upload the next log file!" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` -----------------------------------------------------------------------------------------------" >> /adfipro/logs/ftp.log
mv -f /adfipro/logs/$log_files /adfipro/logs/backup
rm -f /adfipro/logs/$des_files
break
else
cnt_download=`expr $cnt_download + 1` #count number
echo "`date "+%Y-%m-%d %H:%M:%S"` cnt_download=$cnt_download" >> /adfipro/logs/ftp.log
if [ $cnt_download -gt 10 ];then
echo "`date "+%Y-%m-%d %H:%M:%S"` Try more then 10 times! Break!" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` -----------------------------------------------------------------------------------------------" >> /adfipro/logs/ftp.log
rm -f /adfipro/logs/$des_files
break
else
sleep_time_download=`expr $sleep_time_download + 60`
echo "`date "+%Y-%m-%d %H:%M:%S"` $log_files is upload failed! Sleep $sleep_time_download continue to upload this log file until it's upload comletely" >> /adfipro/logs/ftp.log
sleep $sleep_time_download
res=$(ping 8.8.8.8 -c 3 | grep received | awk '{print $4}') #3 is ok; or is failed
if [ $res = 3 ];then
#echo $log_files
echo "`date "+%Y-%m-%d %H:%M:%S"` Res_ping=$res;Network is ok!" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` Begin use ftp to upload the $log_files file!" >> /adfipro/logs/ftp.log
ftp -n -i -v $ftphost << EOF
user $username $passwd
cd $backupdir
lcd $filepath
passive
binary
put $des_files
bye
EOF
fi
continue
fi
fi
 
else
cnt_ping=`expr $cnt_ping + 1` #count number
echo "`date "+%Y-%m-%d %H:%M:%S"` cnt_ping=$cnt_ping" >> /adfipro/logs/ftp.log
if [ $cnt_ping -gt 2 ];then
echo "`date "+%Y-%m-%d %H:%M:%S"` Try 3 times! Break!" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` -----------------------------------------------------------------------------------------------" >> /adfipro/logs/ftp.log
rm -f /adfipro/logs/$des_files
break
else
echo "`date "+%Y-%m-%d %H:%M:%S"` Res_ping=$res;Network is failed! Sleep 60s then continue!" >> /adfipro/logs/ftp.log
sleep 60
continue
fi
fi
done
else
echo "`date "+%Y-%m-%d %H:%M:%S"` Res_ping=$res;Network is failed! Continue!" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` -----------------------------------------------------------------------------------------------" >> /adfipro/logs/ftp.log
rm -f *.tar.gz
sleep 3
continue
fi
else
echo "`date "+%Y-%m-%d %H:%M:%S"` 3G_state=$state;3G is failed! Continue!" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` -----------------------------------------------------------------------------------------------" >> /adfipro/logs/ftp.log
sleep 3
continue
fi
fi
else
#echo "All the log files is upload!" >> /adfipro/logs/ftp.log
sleep 3
continue
fi
done
 
ls /adfipro/logs/ | grep $device_id > log
line=`awk 'END {print NR}' /adfipro/logs/log`
#echo "The line is $line" >> /adfipro/logs/ftp.log
#if [ -s /adfipro/logs/log ];then
if [ $line -eq 2 ];then
echo "`date "+%Y-%m-%d %H:%M:%S"` All the logs is uploaded! Break!" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` ***********************************************************************************************" >> /adfipro/logs/ftp.log
rm -f /adfipro/logs/log
break
else
cnt_upload=`expr $cnt_upload + 1` #count number
echo "`date "+%Y-%m-%d %H:%M:%S"` cnt_upload=$cnt_upload" >> /adfipro/logs/ftp.log
if [ $cnt_upload -gt 2 ];then
echo "`date "+%Y-%m-%d %H:%M:%S"` Try 3 times! Break!" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` ***********************************************************************************************" >> /adfipro/logs/ftp.log
break
else
exist_files=`cat /adfipro/logs/log`
echo "`date "+%Y-%m-%d %H:%M:%S"` The $exist_files is not uploaded;Continue!" >> /adfipro/logs/ftp.log
rm -f /adfipro/logs/log
echo "`date "+%Y-%m-%d %H:%M:%S"` Sleep 300s then continue to upload the $exist_files log files!" >> /adfipro/logs/ftp.log
echo "`date "+%Y-%m-%d %H:%M:%S"` ###############################################################################################" >> /adfipro/logs/ftp.log
sleep 300
continue
fi
fi
done
 

<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值