学习笔记(shell统计前一天apache 访问量存放数据表)

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:405

[font="]今天小练习了一下将前一天apache的访问量存放在数据表里便于管理和查询,分享一下,不足之处请大神们多多指教,代码如下:(本人是小白,请大神们不要笑我哦)[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]#!/bin/bash[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]#logcount.sh[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]
[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]mysql="mysql -uroot -pxz123456"[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]yesterday=`date -d yesterday +%Y%m%d`[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]#echo "$yesterday"[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]yllog="/var/log/httpd/access_log"[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]zylog="/var/log/httpdbak/access_${yesterday}.log"[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]mv $yllog $zylog[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]pkill -1 httpd[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]tmpfile=$$.txt[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]cat $zylog |awk '{print $1}'|sort |uniq -c |awk '{print $2":"$1}'>$tmpfile[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]for i in `cat $tmpfile`[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]do[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]ip=`echo $i |awk -F: '{print $1}'`[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]counts=`echo $i |awk -F: '{print $2}'`[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]sql="insert into test.crontab(date,ip,counts) values('$yesterday','$ip','$counts')"[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]$mysql -e "$sql"[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]done[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]rm -rf $tmpfile[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]sql="select * from test.crontab"[font=Microsoft YaHei, Helvetica, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, Helvetica Neue, Droid Sans, wenquanyi micro hei, FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif]$mysql -e "$sql"[font="]之后写一个执行计划,定于每天凌晨0点执行[font="]crontab -e
00 00 *** /home/zyj/logcount.sh

本文标签:
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】