SHELL训练营--day22_shell练习51-55

#判断网站运行
#!/bin/bash
url="http://www.baidu.com/index.php"
[email protected]

code=`curl -I $url 2>/tmp/curl.err|head -1|awk '{print $2}'`

if [ -z "$code" ]
then
    python mail.py $mail_user "$url 访问异常" "`cat /tmp/curl.err`"
elif [ $code != "200" ]
then
    curl -I $url &>/tmp/curl.log
    python mail.py $mail_user "$url访问异常,状态码$code" "`cat /tmp/curl.log`"
fi

#小于5k文件打包
#!/bin/bash
t=`date +%F`

cd $HOME
tar czf $t.tar.gz `find ./ -type f -size -5k|xargs`

#监控22端口是否被封
#!/bin/bash
iptables -nvL INPUT --line-numbers |grep -w 'dpt:22' |awk '$4 ~/REJECT|DROP/ {print $1}' >/tmp/iptables.log
n=`wc -l /tmp/iptables.log`

if [ $n -gt 0 ]
then
    for n in `tac /tmp/iptables.log`
    do
        iptables -D INPUT $n
    done
fi

#分析日志
#!/bin/bash
export LANG=en
log="/usr/local/nginx/logs/access.log"
t=`date +%d/%b/%Y:1[01]:[0-5][0-9]:`

egrep "$t" $log| awk '{print $1}' |sort -n |uniq -c |sort -n |tail -1 |awk '{print $2}'

#打印数字
#!/bin/bash
read -p "Please input a number:" n
n1=`echo $n |sed 's/[0-9]//g'`
if [ -n "$n1" ]
then
    echo "Please input a number."
    exit
fi

for i in `seq 1 $n`
do
    echo $i
done

read -p "If continue? y/n" c
case $c in
    n|N)
        exit
    ;;
    y|Y)
        read -p "Please input a number:" n2
        n3=`echo $2 |sed 's/[0-9]//g'`
        if [ -n "$n3" ]
        then
            echo "Please input a number."
            exit
        fi
        if [ $n2 -le $n ]
        then
            echo "$n2 should grater than $n."
            exit
        fi

        for i in `seq $[$n+1] $n2`
        do
            echo $i
        done
    ;;
    *)
        echo "Please input a number."
    ;;
esac

猜你喜欢

转载自blog.51cto.com/sincethen/2343574
今日推荐