您的位置:首页 > 运维架构 > Shell

SHELL训练营--day15_shell练习21-25

2019-01-09 00:57 856 查看
#输出文件数字个数,并统计和
#!/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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell