- 论坛徽章:
- 0
|
本帖最后由 永夜之魂 于 2013-07-22 14:05 编辑
1.- awk '{print $NF}' illegal.log |sort -r|uniq -c|sort -rn | head -10
复制代码 2.这里先说一下个人的看法,因为日志超过1G,因此假定,每一分钟都在写入log,这里参照本番环境的log来处理- #!/bin/sh
- _time1=`date -d '-10min' "+%b %-d, %Y %-I:%M:[0-5][0-9] %p"`
- _time2=`date "+%b %-d, %Y %-I:%M:[0-5][0-9] %p"`
- _dir=/home/test
- _tmp1=/tmp/00.tmp
- _tmp2=/tmp/01.tmp
- cd $_dir/
- awk '/$_time1/{p=1}/$_time2/{p=0}p' wls_ms1.out |egrep -iw 'error|critical' -A20 > $_tmp2
- echo -e "To: admin@ChinaUnix.net" > $_tmp1
- if [ -f $_tmp2 ]
- then
- echo -e "Subject: You need check it at $_time2" >> $_tmp1
- cat $_tmp2 >> $_tmp1
- cat $_tmp1 | /usr/sbin/sendmail -t
- rm -rf {$_tmp1,$_tmp2}
- else
- exit
- fi
复制代码 3.- #!/bin/sh
- _dir1=/opt/WebSphere/AppServer/profiles
- _dir2="/var/ChinaUnix"
- _time=date "+%a"
- if [ $_time != "Sun" ]
- then
- for x in {3..100}
- do echo $x
- ssh 192.168.1.$x "tar -czvpf $_dir1/`date "+%Y%m%d"`_incre.tar.gz -g $_dir1/`date "+%Y%m%d"`_tarinfo $_dir1/ --exclude=$_dir1/bin --exclude=$_dir1/logs --exclude="*.log" --exclude="*heapdump*" --exclude="*.gz" --exclude="*.tar" --exclude="*.zip" --exclude="*.bak" --exclude="*.tar.gz" --exclude="*_tarinfo""
- done
- else
- for x in {3..100}
- do echo $x
- ssh 192.168.1.$x "tar -zcvf $_dir1/`date "+%Y%m%d"`_incre.tar.gz $_dir1/ --exclude=$_dir1/bin --exclude=$_dir1/logs --exclude="*.log" --exclude="*heapdump*" --exclude="*.gz" --exclude="*.tar" --exclude="*.zip" --exclude="*.bak" --exclude="*.tar.gz" --exclude="*_tarinfo""
- done
- fi
- for x in {3..100};do echo $x;mkdir -p $_dir2/192.168.1.$x && scp root@192.168.1.$x:$_dir1/{`date "+%Y%m%d"`_incre.tar.gz,`date "+%Y%m%d"`_tarinfo} $_dir2/192.168.1.$x/;done
复制代码 4.- 第一条是command1和command2的真假共同构成了判断条件,二者有任意一个不为真则执行command3;二者皆为真则执行 command1 && command2
- 第二条command1作为唯一判定条件,若为真,结果为command2;若为假,结果为command3
复制代码 5.- echo "1234" |awk '{split($0,a,"");print a[1]+a[2]+a[3]+a[4]}'
复制代码 6.- [root@server test]# awk --version
- GNU Awk 3.1.7
- #!/bin/sh
- echo -e "Please input 1;2"
- read a
- case $a in
- [1])
- echo -e "Please input a date "
- read b
- #awk -v now=" $b" 'BEGIN{t1=mktime("2013 01 01 0 0 0");t2=mktime(now);print (t2-t1)/3600/24}' #与下一行是同样的功能,但二者接受的输入不同
- echo $b |awk '{gsub(/-/," ",$0);t1=mktime("2013 01 00 0 0 0");t2=mktime($0" 0 0 0");print (t2-t1)/3600/24}'
- #echo $b|awk '{gsub(/-/," ",$0);print strftime("%j",mktime($0" 00 00 00"))}'
- ;;
- [2])
- echo -e "Please input a date "
- read c
- echo $c|awk '{gsub(/-/," ",$0);print strftime("%Y-%m-%d",mktime($0" 00 00 00")-24*3600)}'
- esac
复制代码 8.9.- [root@server ~]# vim 00.sh
- #!/bin/bash
- x=00.txt
- touch ./$x
- [root@server ~]# sh -x 00.sh
- + x=00.txt
- + touch ./00.txt
复制代码 |
|