SHELL訓練營--day16_shell練習21-25

#輸出文件數字個數,並統計和 #!/bin/bash sum=0 while read line do line_n=`echo $line|sed 's/[^0-9]//g'|wc -L` echo $line_n sum=$[$sum+$line_n] done < $1 echo "sum:$sum" #對比文件差異 #!/bin/bash dir=/data/web [ -f /tmp/md5.list ] && rm -f /tmp/md5.list find $dir/ -type f > /tmp/file.list while read line do md5sum $line >> /tmp/md5.list done < /tmp/file.list #scp /tmp/md5.list $B:/tmp/ echo "scp /tmp/md5.list $B:/tmp/" [ -f /tmp/check_md5.sh ]&& rm -f /tmp/check_md5.sh cat > /tmp/check_md5.sh <<EOF #!/bin/bash dir=/data/web n=\`wc -l /tmp/md5.list|awk '{print \$1}'\` for i in \`seq 1 $n\` do file_name=\`sed -n "\$i"p /tmp/md5.list |awk '{print $1}'\` md5=\`sed -n "\$i"p /tmp/md5.list | awk '{print $2}'\` if [ -f \$file_name ] then md5_b=\`md5sum \$file_name\` if [ \$md5_b != \$md5 ] then echo "\$file_name changed." fi else echo "\$file_name lose." fi done EOF echo "scp /tmp/check_md5.sh B:/tmp/" echo "esh B '/bin/bash /tmp/check_md5.sh'" # 檢測網卡流量 #!/bin/bash logdir=/tmp/sar_log file=$logdir/`date +%d%H%M`.log [ -d $logdir ] || mkdir -p $logdir LANG=en sar -n DEV 1 50 |grep eth0 |grep "Average" > /tmp/sar.tmp exec >> $file echo "$t" awk '{print "eth0 input:",$5*8000"bps""\n""eth0 output:",$6*8000"bps"}' /tmp/sar.tmp echo "##############" #批量殺進程 #!/bin/bash for pid in `ps aux| grep clearnen.sh|awk '{print $2}'` do echo $pid kill -9 $pid done #判斷WEB服務 #!/bin/bash n=`netstat -lntp |grep ':80 '|wc -l` if [ $n -eq 0 ] then echo "web service is down" else ser=`netstat -lntp|grep ':80 '|awk -f '/' '{print $NF}'|sed 's/ //g'` echo "It is listenning port 80,and the service is $ser" fi
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章