Linux 脚本
Linux日志分析脚本, 用来熟练shell语法
- 日志解析
#!/bin/sh
function filter() {
echo "$1"
if [ `echo $1 | grep -e gz` ];
then
touch temp
cat /dev/null > temp
gunzip -c $1 > temp
cat temp | grep 'com.fantasia.crawler.filter.CountFilter.doFilter(30)' | awk '{print $7}' | awk -F '/' '{print $6}' | sort | uniq
else
cat $1 | grep 'com.fantasia.crawler.filter.CountFilter.doFilter(30)' | awk '{print $7}' | awk -F '/' '{print $6}' | sort | uniq
fi
echo -e "end $1\n"
}
echo "root path: $1"
echo "begin loop"
for i in `ls $1`
do
if [ `echo $i | grep -e info.log` ]
then
filter "$1$i"
fi
done
exit 0
- awk if判断字符串包含
cat $1 | grep 'com.fantasia.crawler.filter.CountFilter.doFilter(30)' | awk '{print $7}' | awk -F '/' '{if ($6=="review" && $7~/amazon/) {print $7; } else if ($6=="review") {print $7 " " $8;} }' | sort | uniq
- awk if判断正则表达式
awk '{if($0!~/info/ && $0~/[a~z]/){print $0;}}'