#!/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
我知道简单的方法就是比较另一个变量中的内容,但我真的希望将比较保持在一行中。所以如果有人能帮助我,我会非常感激
答案 0 :(得分:2)
diff
和grep
都支持-q
。直接在if
语句中使用它们,而不是捕获它们的输出并单独比较它。