Question

#!/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

I know the easy way would just be to compare the content in another variable but i REALLY want to keep the comparison in one line. So if anyone can help me I would greatly appreciate it

Was it helpful?

Solution

diff and grep both support -q. Use them directly in the if statements instead of capturing their output and comparing it separately.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top