1
#!/bin/bash
#James Kenaley 20120513
#Server Monitor Script
while read -r name ip content
do
    ip_status=`ping -w1 $ip | grep -c "100%"`
    web_status=`nmap -n -PN -p 80 $ip | grep -c open`
    ssh_status=`nmap -n -PN -p 22 $ip | grep -c open`
    content_status=`diff <(curl -s $ip | md5sum) <(cat $content) | grep -c -e "<" -e ">"`
    if [ $web_status -eq 1 ]
    then
            echo "The webserver is running on $name @ $ip"
    else
            echo "  The webserver is offline on $name @ $ip"
    fi

    if [ $ssh_status -eq 1 ]
    then
            echo "SSH is enabled on $name @ $ip"
    else
            echo "  SSH has been disabled on $name @ $ip"
    fi

    if [ $content_change -gt 0 ]
    then
            echo "  The content has changed on $name's webserver"
    else
            echo "The content is the same"
    fi
done < server.list

簡単な方法は別の変数の内容を比較することですが、私は本当に比較を1行に収めたいと思っています。だから誰かが私を助けることができれば私はそれを大いに感謝します

4

1 に答える 1

2

diffgrep両方のサポート-qif出力をキャプチャして個別に比較するのではなく、ステートメントで直接使用してください。

于 2012-05-16T02:15:39.330 に答える