#!/bin/sh savepath=/root/tar/$(date +%F_%H%M) if [ ! -d $savepath ] # !與 -d 之間要加空格,與[] 之間要有空格 then mkdir -p $savepath fi tar -jPcf $savepath/96.tar /www/wwwroot/default/96weixin.ewm
!/bin/sh file=/root/ip.txt for val in `cat $file` do iptables -I INPUT -s$val -j DROP echo $val done
結果:linux
[root@iZryxshkbkz2x2Z ~]# iptables -nvL Chain INPUT (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source destinatio 0 0 DROP all -- * * 66.55.44.33 0.0.0.0/0 0 0 DROP all -- * * 12.4.5.6 0.0.0.0/0 0 0 DROP all -- * * 66.55.44.33 0.0.0.0/0 0 0 DROP all -- * * 12.4.5.6 0.0.0.0/0 124 6000 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:888 1169 55324 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpts:39000:40000 752 36764 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 s
[root@iZryxshkbkz2x2Z wwwlogs]# cat access.log| grep -io 'HTTP\/1.[10]"[[:bla nk:]][0-9]\{3\}' | awk '{print $2}' 403 404
#!/bin/sh filepath=/www/wwwlogs/access.log getStatus(){ httpStatus=`cat $filepath | grep -io 'HTTP\/1.[10]"[[:blank:]][0-9]\{3\}' | awk '{ if($2>=100&&$2<200) {i++} else if($2>=200&&$2<300 ) {j++} else if($2>=300&&$2<400) {m++} else if($2>=400&&$2<500) {n++} else if($2>=500) {p++} else {a++} }END{ print i?i:0, j?j:0, m?m:0, n?n:0, p?p:0, a?a:0 }' ` echo -e "${httpStatus}" } getStatus
執行結果: 0 17 2 662 0 0nginx
4 linux 分析系統內存tcp
4-1 經過free -m 分析系統內存: free -m:rest
[root@iZryxshkbkz2x2Z default]# free -m total used free shared buffers cached Mem: 996 885 110 103 64 456 -/+ buffers/cache: 365 630 Swap: 1024 57 967 [root@iZryxshkbkz2x2Z default]# free -m |sed -n '2p' | awk 'used=($3-$6-$7),rest=($6+$7+$4){print "總內存:" $2,"已用內存:" $3-$6-$7 ,"剩餘內存:"$6+$7+$4}END{printf "使用百分比:%10d%\n",(used/$2)*100 }' 總內存:996 已用內存:365 剩餘內存:630 使用百分比: 36%
4-2 經過 proc/meminfo 分析系統內存:code
[root@iZryxshkbkz2x2Z default]# cat /proc/meminfo | awk '/MemTotal/{total=$2}/MemFree/{free=$2}/^Cached/{cache=$2}/Buffers/{buffers=$2}END{printf "系統已用內存:%10d\n", (total-free-cache-buffers)/1024}' 系統已用內存: 343
[root@iZryxshkbkz2x2Z ~]# df -h | grep -Ev 'Filesystem|tmpfs' | awk '{print "總磁盤空間:" $2, "已使用空間:" $3,"使用率:" $5}' 總磁盤空間:40G 已使用空間:5.4G 使用率:15%
寫的語句不太好,有空重寫。ip
未完待續。。。。內存