`

Linux 常用脚本

 
阅读更多

1:sort -k 10 -t ' ' -n localhost_access_log.2015-01-29.txt 

      用第10列按照数字排序,列分隔符为空格。默认安空格

2:sort aa.txt | uniq  -c 

     统计重复数

3:cat localhost_access_log.2015-01-29.txt | cut -f1 -d ' ' | sort | uniq -c |sort -k 1 -n -r | head -10:

  统计访问量排名前10 的Ip

4:total=`wc -l localhost_access_log.2015-01-29.txt | cut -f1 -d " "` && not_total=`awk '$9 ==404{print $9,$1}' localhost_access_log.2015-01-29.txt | wc -l`&& expr $not_total \* 100 / $total

     统计 404占比

5: sed 's/Jan/xx/' localhost_access_log.2015-01-29.txt | head -10

      替换文件中Jan字符为xx

6:sed '/qq/d' localhost_access_log.2015-01-29.txt

     删除包含qq的行

7:{

    if(map[$7]>0){

   map[$7]=map[$7]+$10

   map_time[$7]=map_time[$7]+1

  }else{

    map[$7]=$10

   map_time[$7]=1

   }

}

END{

   for(i in map){

    print i "=" map[i]/map_time[i];

}

}

  awk -f  awk_test access.log

   输出每个URL的平均访问时间

8:

cup 使用率 :top -n 1 | sed -n 1p | awk '{print $12}'

  磁盘使用率:  df -h | sed -n '3,5p'| awk '{print $1,$(NF-1)}'

 

load=`top -n 1 | sed -n '1p' | awk '{print $12}'`
load=${load%\,*}
disk_usage=`df -h | sed -n '3p'| awk '{print $(NF-1)}'`
disk_usage=${disk_usage%\%*}
overhead=`expr $load \> 2.00`
if [ $overhead -eq 1 ]; then
  echo "error"
else
echo "succcess"
fi
if [ $disk_usage -gt 50 ]; then
  echo "error"
else
echo "success"
fi
exit 0
 
9: 循环读取文件打印输出行
ACCESS_FILE=/tmp/test/test.tt
while read LINE
do
OLD_IFS="$IFS"
IFS=" "
filed_arr=($LINE)
IFS="$OLD_IFS"
echo ${filed_arr[0]}
done < $ACCESS_FILE
exit 0
 
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics