- 论坛徽章:
- 0
|
本帖最后由 cyaln 于 2013-06-27 12:02 编辑
第一题
- #!/bin/bash
- awk -F '\t' '{print $6}' illegal.log | sort > newfile.log
- awk '{a[$0]++}END{for (b in a)print a[b],b}' newfile.log | sort -nr | head -n 10
- rm -rf newfile.log
复制代码
- ----------------------RESULT-------------------
- 70 220.250.52.66
- 36 220.250.58.170
- 30 220.250.58.171
- 29 220.250.52.90
- 28 220.250.58.172
- 27 142.4.117.83
- 23 111.73.45.13
- 22 222.186.26.26
- 19 74.91.23.27
- 16 91.237.249.67
复制代码 第二题
- #!/bin/bash
- f=/tmp/wls_ms1.out
- for n in 10 9 8 7 6 5 4 3 2 1
- do
- m10=$(date -d "${n} minutes ago" "+%k:%M")
- echo $m10
- data=$(awk '/'"$m10"'/, /^b/{print $0}' $f |grep 'Error')
- if [[ -n $data ]]; then
- echo "$data" | mail -s 'Error' admin@ChinaUnix.net
- exit 0
- else
- :
- fi
- done
复制代码 第三题- we=$(data +%w)
- #差异备份
- cb () {
- for n in $(seq 3 100)
- do
- ssh 192.168.1.${n} << EOF
- find /opt/WebSphere/AppServer/profiles -mtime 1 -type f ! -name "*.log" ! -name "*heapdump*" ! -name "*.gz" ! -name "*.tar" ! -name ".zip" ! -name "*.bak" |egrep -v "/bin|/log" > /tmp/$.log
- tar -cz -T /tmp/$.log -f /tmp/$n.tar.gz
- scp /tmp/${n}.tar.gz 192.168.1.2:/var/ChinaUnix/
- EOF
- done
- }
- #完全备份
- wb () {
- for n in $(seq 3 100)
- do
- ssh 192.168.1.${n} << EOF
- find /opt/WebSphere/AppServer/profiles -type f ! -name "*.log" ! -name "*heapdump*" ! -name "*.gz" ! -name "*.tar" ! -name ".zip" ! -name "*.bak" |egrep -v "/bin|/log" > /tmp/$.log
- tar -cz -T /tmp/$.log -f /tmp/$n.tar.gz
- scp /tmp/${n}.tar.gz 192.168.1.2:/var/ChinaUnix/
- EOF
- done
- }
- if [[ "$we" -eq 0 ]]; then
- wb
- else
- cb
- fi
复制代码 第四题
- 1. command1 && command2 || command3 此种表达式是一个完整的判断,意味着command1 和command2 同时成立,如果有一个不成立,则执行command3
- 2. if command1 then command2 else command3 fi 此种表达式是一个if-else结构的,意味着若command1为真执行command2,反之command1为假执行command3.
复制代码 第五题
- #!/bin/bash
- declare -i rock=0
- NUM=$1
- for((i=0;i<${#NUM};i++));
- do
- rock=rock+${NUM:$i:1};
- echo $rock;
- done
复制代码
- ----------------------RESULT-----------------------
- ./script_name 12345
- 15
复制代码 第六题
- ------------------------RESULT--------------------------
- ./script_name 2013-06-23
- Today is the 175 days in this year!!!
- Yesterday is 2012-06-22 !!!
复制代码 第七题
- 说明
- 1.程序中出现array=(8)。根据权重值,九宫格的第一行第一列的值为7or8,由于 需要满足题目的另外一个要求,所以这里必须为8. (权重计算: 1.1 200 1.2 110 1.3 101 2.1 110 2.2 20 2.3 11 3.1 101 3.2 11 3.3 2 由于4446是指定的结果,可以当做极限值. 故1.1的值范围200*x>4446/666*200,x=7 or 8)
- 2.程序中出现array[${#array[@]}+1]=1。根据行、列值必须是奇数,所以1.3 2.3 3.1 3.2 3.3为奇数,而且1-9中所有奇数和的个位数为5,必须+1才为6.此时只有3.3是被多加了1次.故3.3也必须为1.
- 3.判断奇偶按位写是难点。
- 4.程序还是有不足的地方,就是array[1]的值恒为空,没时间弄了(女儿要睡觉了),求达人解惑。
- 5.求完美、高效答案
复制代码
- ---------------------------RESULT---------------------------
- 869 849 847 867 847 849 867 869
- 423 623 623 423 625 625 425 425
- 751 751 951 951 931 931 931 731
复制代码 第八题
- 可以删除. 因为*是通配符,匹配0个或多个.而有空格的文件,一般会以反斜杠加空格的表示空格 [redhat 2.6.18-194.el5 验证]
复制代码 第九题
- bash执行的数序就是如下:
- brace expansion,
- tilde expansion,
- parameter、variable、arithmetic expansion 、command substitution
- word splitting
- pathname expansion
- 例子:
- echo "${!var^^}"
- # ...is equivalent to
- eval 'echo "${'"$var"'^^}"'
复制代码 第十题
- 1. ls | grep -v '^20130605'
- 2. for ((i=1;i<`ls | wc -l`;i++));do mv "$(ls |sed -n ${i}p)" "$(ls |sed -n ${i}p|sed -e 's/\[//g' -e 's/\]//g' -e 's/ //g' )";done
- 3.
- #!/bin/bash
- for n in $(ls dirA)
- do
- if [[ -f dirA/${n} && -f dirB/${n} ]]
- then
- diff dirA/${n} dirB/${n} >/dev/null
- if [ "$?" -eq 0 ]
- then
- rm -rf dirB/${n}
- else
- :
- fi
- fi
- done
- 4.
- #!/bin/bash
- for n in $(ls dira/ dirb/ |awk '!/dirb\/:|dira\/:/{print $0}')
- do
- m=$(echo $n |awk -F '.' '/XQF$/{print $1}')
- rm -f dira/${m}.che
- rm -f dirb/${m}.che
- done
复制代码 |
|