我怎么做这个工作?

时间:2012-05-16 02:12:15

标签: linux bash grep diff md5sum

#!/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 个答案:

答案 0 :(得分:2)

diffgrep都支持-q。直接在if语句中使用它们,而不是捕获它们的输出并单独比较它。