工作中实用shell脚本与语句
来源:互联网 发布:搜狗输入法 编程皮肤 编辑:程序博客网 时间:2024/06/13 10:48
工作中常见Shell,结合Awk
统连接状态篇:
1.查看TCP连接状态
netstat-n|awk'/^tcp/{++S[$NF]}END{for(ainS)printa,S[a]}'
2.查找请求数请20个IP(常用于查找攻来源):
netstat-anlp|grep80|greptcp|awk'{print$5}'|awk-F:'{print$1}'|sort|uniq-c|sort-nr|head-n20
netstat-ant|awk'/:80/{split($5,ip,":");++A[ip[1]]}END{for(iinA)printA[i],i}'|sort-rn|head-n20
3.用tcpdump嗅探80端口的访问看看谁最高
tcpdump-ieth0-tnndstport80-c1000|awk-F"."'{print$1"."$2"."$3"."$4}'|sort|uniq-c|sort-nr|head-20
4.查找较多time_wait连接
netstat-n|grepTIME_WAIT|awk'{print$5}'|sort|uniq-c|sort-rn|head-n20
5.找查较多的SYN连接
netstat-an|grepSYN|awk'{print$5}'|awk-F:'{print$1}'|sort|uniq-c|sort-nr|more
6.根据端口列进程
netstat-ntlp|grep80|awk'{print$7}'|cut-d/-f1
网站日志分析篇1(Apache):
1.获得访问前10位的ip地址
cataccess.log|awk'{print$1}'|sort|uniq-c|sort-nr|head-10
cataccess.log|awk'{counts[$(11)]+=1};END{for(urlincounts)printcounts[url],url}'
2.访问次数最多的文件或页面,取前20
cataccess.log|awk'{print$11}'|sort|uniq-c|sort-nr|head-20
3.列出传输最大的几个exe文件(分析下载站的时候常用)
cataccess.log|awk'($7~/\.exe/){print$10""$1""$4""$7}'|sort-nr|head-20
4.列出输出大于200000byte(约200kb)的exe文件以及对应文件发生次数
cataccess.log|awk'($10>200000&&$7~/\.exe/){print$7}'|sort-n|uniq-c|sort-nr|head-100
5.如果日志最后一列记录的是页面文件传输时间,则有列出到客户端最耗时的页面
cataccess.log|awk'($7~/\.php/){print$NF""$1""$4""$7}'|sort-nr|head-100
6.列出最最耗时的页面(超过60秒的)的以及对应页面发生次数
cataccess.log|awk'($NF>60&&$7~/\.php/){print$7}'|sort-n|uniq-c|sort-nr|head-100
7.列出传输时间超过30秒的文件
cataccess.log|awk'($NF>30){print$7}'|sort-n|uniq-c|sort-nr|head-20
8.统计网站流量(G)
cataccess.log|awk'{sum+=$10}END{printsum/1024/1024/1024}'
9.统计404的连接
awk'($9~/404/)'access.log|awk'{print$9,$7}'|sort
10.统计httpstatus.
cataccess.log|awk'{counts[$(9)]+=1};END{for(codeincounts)printcode,counts1}'
cataccess.log|awk'{print$9}'|sort|uniq-c|sort-rn
10.蜘蛛分析
查看是哪些蜘蛛在抓取内容。
/usr/sbin/tcpdump-ieth0-l-s0-w-dstport80|strings|grep-iuser-agent|grep-i-E'bot|crawler|slurp|spider'
数据库篇
1.查看数据库执行的sql
/usr/sbin/tcpdump-ieth0-s0-l-w-dstport3306|strings|egrep-i'SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL'
- 工作中实用shell脚本与语句
- 实用的shell脚本
- linux shell 实用脚本
- shell脚本实用知识点
- shell脚本中执行mysql语句
- Shell 脚本中执行mysql语句
- Shell脚本中执行mysql语句
- shell脚本中if语句的用法
- shell脚本中$@与$#区别
- Shell脚本学习(二):条件语句与循环语句
- Android开发中高效实用的shell命令脚本
- 工作邮件中超实用的英文语句
- 工作记录--shell脚本
- shell脚本:if语句
- shell脚本:for语句
- shell脚本:while语句
- LINUX shell 脚本语句
- shell 脚本 if 语句
- Linux负载均衡软件LVS之一(概念篇)
- android 解码出来的视频frame数据,是如何一步步的传递到显示端的(使用 GPU offline 合成)
- java编程思想(读书笔记):9.持有你的对象
- leetcode303-range sum query-python
- 3种LVS/Nginx/HAProxy负载均衡器的对比分析
- 工作中实用shell脚本与语句
- java泛型(二)、泛型的内部原理:类型擦除以及类型擦除带来的问题
- hdu 1081 to be max
- java泛型(三)、通配符的使用
- [LeetCode]029-Divide Two Integers
- cmd的forfiles命令详解
- linux c++ 利用timerfd和epoll封装计时器(Timer)类
- 大型网站架构演化历程
- android stdio安装记录