#!/bin/bash
yesterday=`date -d yesterday +%y-%m-%d` #get date of yesterday
dev_num=`seq -f '%04g' 18 18`
tar_error=-1
#FTP server
ftphost="119.188.10.163"
username="adfi_ftp"
passwd="adfi1!"
#FTP server log dirdecty
ftp_dir="log"
for dir in $dev_num
do
cp file_$dir $dir/
cd $dir
ls *.gz -l > file_new_$dir
file_create=`diff file_$dir file_new_$dir | awk '{if ($9 != '\n') \
print $9}' | xargs`
echo $file_create
#judge whether exit new file
judge_file_create=`echo $file_create | awk 'NR == 1 {print $1}'`
if [ -s $judge_file_create ]
then
echo $judge_file_create
for i in $file_create
do
dev=`echo $i | awk -F "." '{print $3}'`
date=`echo $i | awk -F "." '{print $4}'`
file_type=`echo $i | awk -F "." '{print $1}'`
#which type to disdinguish this file is, retrain apache file get
# rid of dhcp file
if [ $file_type != "apache" ]
then
continue
fi
echo $i
apache_file1=`tar -xvf $i`
# delete the file which cannot tar to file
tar_stat=`echo $?`
if [ $tar_stat -gt 0 ]
then
echo "apache: $date $tar_error " >> ../log.$dir
rm $i
continue
fi
apache_num=`cat $apache_file1 | awk '{print $1}' | sort | uniq | \
sed '/::1/d' | wc -l`
echo "apache: $date $apache_num " >> ../log.$dir
# add stat the most number of vistors which vistor device url
film_pick=`cat $apache_file1 | awk '{if($9 == 200)print $7}' | grep /media/?cat`
film_each_pick=`cat $apache_file1 | awk '{if($9 == 200)print $7}' | grep /media/?p`
html_pick=`cat $apache_file1 | awk '{if($9 == 200)print $7}' | grep '.html\>'`
echo "$date frequency and url :" >> ../url.log.$dir
echo $film_pick $film_each_pick $html_pick | sed 's/ /\n/g' | sort | uniq -c | \
sort -nr | head -15 >> ../url.log.$dir
echo "***********end************" >> ../url.log.$dir
done
for i in $file_create
do
dev=`echo $i | awk -F "." '{print $3}'`
date=`echo $i | awk -F "." '{print $4}'`
file_type=`echo $i | awk -F "." '{print $1}'`
#which type to disdinguish this file is
if [ $file_type != "dhcp" ]
then
continue
fi
echo $i
dhcp_file1=`tar -xvf $i`
# delete the file which cannot tar to file
tar_stat=`echo $?`
if [ $tar_stat -gt 0 ]
then
echo "dhcp: $date $tar_error " >> ../log.$dir
rm $i
continue
fi
dhcp_num=`cat $dhcp_file1 | awk '{print $5}' | sort | uniq | wc -l`
echo "dhcp: $date $dhcp_num " >> ../log.$dir
done
mv file_new_$dir ../file_$dir
cd ..
fi
done