您的位置:首页 > 运维架构 > Shell

shell 笔记

2014-01-21 14:29 218 查看
sed -r 's/.+(type)=([0-9]+).+/\2/' file

echo f1 f2 f3| xargs -i  -n 1 mv {} {}.bak

pptp:
kill `ps -ef | grep pptp | awk '{print $0}' | grep 100.10[6-7] | awk '{print $2}'`

egrep "HTTP/1.1\" 5.. " api_xxx_access.log-20131017 |awk '{ print $8}' | awk -F "&" '{print $1,$2}' | sort  | uniq -c | sort -rn | head -10

date -s "10/12/13 16:58:59" +%s

awk多行处理:
awk '{if(NR>1&&!/ms/){ print "";printf $0;} else {printf $0" ";} }' datafile

hostip=`/sbin/ip a | grep -E "eth[0-9]$|em[0-9]$|bond[0-9]$|br[0-9]$" |grep "/2" | awk '{print $2}'|awk -F "/" '{print $1}' | awk -F '.' '$3 < 4 {print $0}'` | grep 192.168

hostname -i

磁盘使用量:
df -Tm | grep "[0-9] " | awk '{sub(/%/,"");$6} {if($6 > 90 && $5 < 1000000) {print $0}}'

脚本日志检索:
ztime=`date "+%Y-%m-%d %H:%M" -d "-15 minutes"`

startnum=`cat /www/logs/application.log | grep -n "${ztime}:" | head -1 | awk -F ":" '{print $1}'`
num=$(cat /www/logs/application.log | sed -n "${startnum},\$p" | grep "check comment" -c)

crontab处理:
crontab -l | grep -v ^# |  grep -Eo '/[a-z]+.*[\w_]+.*\.sh|/[a-z]+.*[\w_]+.*\.py' | awk '{print $NF}'

检索日志:
a=`date +%H:%M:%S`
b=`date +%H:%M:%S -d "-5 mins"`
c=`awk -F "[ |,]" '$1>="'$b'"&&$1<="'$a'"{print}' /usr/local/tomcat_chengxu2/logs/solr.log

awk,两文件合并:
awk 'FILENAME==ARGV[1]{a[FNR]=$1;b[FNR]=$2};FILENAME==ARGV[2]{for(i=1;i<=length(a);i++){if(a[i]==$1){print a[FNR],b[FNR],$2}}}' /tmp/file1 /tmp/file2 | sort -k2

read line with command:
echo `cat ${1}error.log.$dtime  | grep "110: Connection timed out" | grep -oP "192.168.[0-9.]+:[0-9]+" | sort | uniq -c | sort -rn | awk -v yuzhi=$zhi '$1 > yuzhi {print $1,$NF}'` | while read line
do
echo $line
done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell 笔记