0 SHELL训练营--day24_shell练习61-65

# 找文件差异。grep -vf b.txt a.txt
#!/bin/bash
cat a.txt |while read line
do
    if ! grep -q "$line" b.txt
    then
        echo $line
    fi
done >c.txt
wc -l c.txt

#杀进程
#!/bin/bash
ps -u $USER |awk '$NF ~ /aming/ {print $1}' |xargs kill

#并发备份数据库
#!/bin/bash
N=5
mysql -uaming -ppasswd mydb -e "show tables"|sed '1d' >/tmp/table.txt

n=`wc -l /tmp/table.txt|awk '{print $1}'`

div()
{
    n=`echo "scale=1;$1/$2"|bc`
    n1=`echo "scale=1;$n+0.5"|bc`
    echo $n1|cut -d. -f1
}

n1=`div $n $N`
split -l $n1 /tmp/table.txt

myd()
{
    for t in `cat $1`
    do
        mysqldump -uaming -ppasswd mydb $t > $t.sql
    done
}

for f in xaa xab xac xad xae
do
    myd $f &
done

wait

tar czf mydb.tar.gz *.sql
rm -f *.sql

#监控CDN
#!/bin/bash
s_ip=88.88.88.88
url=www.default.com/index.php
ipf=/data/ip.list

curl-x$s_ip:80 $url 2>/dev/null >/tmp/source.txt
for ip in `cat $ipf`
do
    curl -x$ip:80 $url 2>/dev/null >/tmp/$ip.txt
    diff /tmp/source.txt /tmp/$ip.txt >/tmp/$ip.diff

    n=`wc -l /tmp/$ip.diff|awk '{print $1}'`
    if [ $n -gt 0 ]
    then
        echo "节点$ip 有异常。"
    fi
done

#破解字符串
#!/bin/bash
for i in `seq 0 32767`
do
    m=`echo $i|md5sum |cut -c 1-8 `
    echo $i $m
done > /tmp/md5.txt

cat > c.txt <<EOF
21029299
00205D1C
A3DA1677
EOF

grep -f c.txt /tmp/md5.txt
上一篇:shell训练DAY24


下一篇:shell实战训练营Day24