shell 指令碼集合記錄

來源:互聯網
上載者:User
#!/bin/bashcat 1 | grep " 403 " | while read linedo        index=`expr index "$line" GET`        let startindex=$index+3        echo "startindex:"$startindex        endindex=`expr index "$line" \?`        echo "endindex:"$endindex        if [ 0 -eq $endindex ];        then                echo $line                endindex=`expr index "$line" HTTP`                echo "endindex:"$endindex                let urllength=$endindex-$startindex-1                echo "urllength:"$urllength        else                let urllength=$endindex-$startindex-1                echo "urllength:"$urllength        fi        if [ $urllength -gt 0 ];then                url=${line:$startindex:$urllength}                echo "url:"$url                url403="${url403} ${url}"        fi        #echo $url403done

#!/bin/bashcd /opt/logs/time=`date -d "-4 min"  +%Y-%H-%M`echo $timedate=`date -d "-4 min" +'%Y-%m-%d %H:%M:%S'`echo $datefile=`ls |grep $time`echo $file#find 403 urlurl403=`cat $file | grep " 403 " | cut -d " " -f 11 --output-delimiter="\n"`#echo $url403length=`echo $url403 | wc -c`echo "length:"$lengthif [ $length -gt 500 ];then        url403=${url403:0:500}fiif [ -z "$1" ]then        code200=`cat $file | grep -c " 200 "`        echo $code200        code403=`cat $file | grep -c " 403 "`        echo $code403        code404=`cat $file | grep -c " 404 "`        echo $code404        insert_sql="insert into responseCode(create_time,code200,code403,code404,url403) values(\"$date\",\"$code200\",\"$code403\",\"$code404\",\"$url403\")"else       code200=`cat $file | grep "$1" | grep -c " 200 "`        echo $code200        code403=`cat $file | grep "$1" | grep -c " 403 "`        echo $code403        code404=`cat $file | grep "$1" | grep -c " 404 "`        insert_sql="insert into responseCode(create_time,code200,code403,code404,url,url403) values(\"$date\",\"$code200\",\"$code403\",\"$code404\",\"$1\",\"$url403\")"fimysql -h 10.10.77.46 -uroot -pfanfan test -e "${insert_sql}"#rm -rf $file

#!/bin/bash#set -xcd /opt/logsadd_day=0ip_day=0add_hour=0ip_hour=0message=""DATE=`date +'%Y-%m-%d'`time=`date +'%Y-%m-%d %H:%M:%S'`path=/opt/mail/mail$DATE.logecho $pathfunction statics(){        date=`date -d "-3 min" +'%H-%M'`        echo $date        min=`date -d "-3 min" +'%M'`        hour=`date -d "-3 min" +'%H'`        echo "min="$min        echo "hour="$hour        files=`ls | grep "$date"`        echo '[start]'        addCount=`cat $files | grep 'v.jhtml' | grep -c 'add'`        echo addCount=$addCount        let add_day=add_day+$addCount        let add_hour=add_hour+$addCount        echo "add_hour="$add_hour        ipCount=`cat $files| grep 'v.jhtml' | grep 'add' | cut -d ' ' -f3 | sort -u | wc -l`       echo ipCount=$ipCount        let ip_day=ip_day+$ipCount        let ip_hour=ip_hour+$ipCount        echo "ip_hour="$ip_hour        ###########insert into datadabase        insert_sql="insert into T_addCount(create_time,ip_count,add_count) values(\"$time\",\"$addCount\",\"$ipCount\")"        mysql -h 10.10.77.46 -uroot -pfanfan test -e "${insert_sql}"        if [ $min = "15" ] ; then               echo "<br />---Hour Report:---">>$path                echo $DATE" "<br />$date>>$path                echo "<br />add count="$add_hour>>$path                echo "<br />ip count="$ip_hour"<br />">>$path                add_hour=0                ip_hour=0        fi        if [ $date = "17-15" ] ; then                echo "<br /><strong>Day Report:"</strong>$path                echo "<br />"$DATE" "$date>>$path                echo "<br />add counts in yesterday:"$add_day>>$path echo "<br />ip counts in yesterday:"$ip_day>>$path                add_day=0                ip_day=0                #sendmail                curl  -F "format=html" -F "from=xiegang@sohu-inc.com" -F "to= julywang@sohu-inc.com " -F "subject=add and ip statistics" -F "body= `cat  ${path}`" http://10.15.2.57/cgi-bin/alert.py        fi        echo '[end]'}c=1while [ $c -le 2 ]do        statics        sleep 1mdone

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.