- 论坛徽章:
- 0
|
本帖最后由 zhujinzz 于 2013-07-04 00:47 编辑
1- awk '{print $NF}' illegal.log | sort | uniq -c | sort -nr | head -n 10
复制代码 2- #!/bin/base
- cur_time=`date +%s`
- begin_time=`expr $cur_time - 600`
- cur_log_time=`date -d"1970-01-01 UTC ${cur_time} seconds" "+%b %d, %Y %H:%M"`
- cur_pat=`echo ${cur_log_time} | sed 's/.$//g'`
- begin_log_time=`date -d"1970-01-01 UTC ${begin_time} seconds" "+%b %d, %Y %H:%M"`
- begin_pat=`echo ${begin_log_time} | sed 's/.$//g'`
- awk '$0~/'${begin_pat}'/{print NR,$0}' wls_ms1.out > /tmp/wls_ms1.out.tmp
- awk '$0~/'${cur_pat}'/{print NR,$0}' wls_ms1.out >> /tmp/wls_ms1.out.tmp
- for((i=1;i<601;i++))
- do
- begin_time=`expr ${begin_time} + 1`
- begin_pat=`date -d"1970-01-01 UTC ${begin_time} seconds" "+%b %d, %Y %H:%M"`
- begin_line=`awk '$0~/'${begin_pat}'/{print $1}' /tmp/wls_ms1.out.tmp`
- if [ "X${begin_line}" != "X" ];then
- break
- fi
- done
- for((i=1;i<601;i++))
- do
- cur_time=`expr ${cur_time} - 1`
- cur_pat=`date -d"1970-01-01 UTC ${cur_time} seconds" "+%b %d, %Y %H:%M"`
- cur_line=`awk '$0~/'${cur_pat}'/{print $1}' /tmp/wls_ms1.out.tmp`
- if [ "X${cur_line}" != "X" ];then
- break
- fi
- done
- sed -n "${begin_line},${cur_line}p" wls_ms1.out > /tmp/log.file
- error_log = `grep '<error>' /tmp/log.file`
- if [ "X${error_log}" != "X" ];then
- sendMail xxxxx
- fi
复制代码 3- #!/bin/bash
- sdir="/opt/WebSphere/AppServer"
- ddir="/var/ChinaUnix"
- back_program () {
- cur_time=$1
- ip=$2
- if [ "${cur_time}" -ne 7 ];then
- ssh root@${ip}<<EOF
- tar -g /opt/snapshot \
- --exclude="bin" \
- --exclude="log" \
- --exclude="*.log" \
- --exclude="*heapdump*" \
- --exclude="*.gz" \
- --exclude="*.tar" \
- --exclude="*.zip" \
- --exclude="*.bak" \
- -czf /opt/profiles_increment_${ip}_${cur_time}.tar.gz ${sdir}/profiles
- EOF
- else
- ssh root@${ip}<<EOF
- tar -czf /opt/profiles_full_${ip}_${cur_time}.tar.gz \
- --exclude="bin" \
- --exclude="log" \
- --exclude="*.log" \
- --exclude="*heapdump*" \
- --exclude="*.gz" \
- --exclude="*.tar" \
- --exclude="*.zip" \
- --exclude="*.bak" \
- ${sdir}/profiles
- EOF
- fi
- }
- c_time=`date +%u`
- for((i=3;i<101;i++))
- do
- back_program "${c_time}" "192.168.1.${i}"
- if [ "${c_time}" -ne 7 ];then
- /usr/bin/scp root@192.168.1.${i}:/opt/profiles_increment_192.168.1.${i}_${c_time}.tar.gz ${ddir}/
- ssh root@192.168.1.${i} "rm -f /opt/profiles_increment_192.168.1.${i}_${c_time}.tar.gz"
- else
- /usr/bin/scp root@192.168.1.${i}:/opt/profiles_full_192.168.1.${i}_${c_time}.tar.gz ${ddir}/
- ssh root@192.168.1.${i} "rm -f /opt/profiles_full_192.168.1.${i}_${c_time}.tar.gz"
- fi
- done
复制代码 4- command1 && command2 || command3
- 1 command1 False,则command3
- 2 command1 True,则command2,if True,则exit,if False,则command3
- if command1
- then
- command2
- else
- command3
- fi
- 1 command1 True 则command2,否则command3
复制代码 5- #!/bin/bash
- nums=$1
- if [ $# -ne 1 ];then
- echo "Usage:./num_add.sh num(eg 123901)"
- exit 1
- fi
- n_nums=$((${#nums}-1))
- sum=0
- for i in `seq 0 ${n_nums}`
- do
- arr[$i]=${nums:$i:1}
- sum=`expr $sum + ${arr[$i]}`
- done
- echo ${sum}
复制代码 6- #!/bin/bash
- t=$1
- if [ $# -ne 1 ];then
- echo "Usage:./time.sh time(2013-05-23)"
- exit 1
- fi
- sz=`echo ${t} | grep ':'`
- if [ "X$sz" != "X" ];then
- sec=`echo "${t}" | awk '{gsub(/-/," ",$0);gsub(/:/," ",$0);print mktime($0)}'`
- sec1=`expr $sec - 86400`
- echo "$sec" | awk '{day=strftime("%j",'$sec');print day}'
- echo "$sec" | awk '{day=strftime("%j",'$sec1');print day}'
- else
- t="$t 00:00:00"
- sec=`echo "${t}" | awk '{gsub(/-/," ",$0);gsub(/:/," ",$0);print mktime($0)}'`
- sec1=`expr $sec - 86400`
- echo "$sec" | awk '{day=strftime("%j",'$sec');print day}'
- echo "$sec1" | awk '{day=strftime("%j",'$sec1');print day}'
- fi
复制代码 8 可以,这里是通配符,测试结果如下- [test@test test]$ ll
- 总用量 4
- -rw-r--r-- 1 test test 87 7月 4 00:44 a .log
- [test@test test]$ rm *
- [test@test test]$ ll
- 总用量 0
- [test@test test]$
复制代码 |
|