#!/bin/bash
# This lame script checks for presence of a certain content passed as a parameter on the command line
# it makes use of lynx and good ol' grep, use the string you want to search as the 1st parameter,
# enclosing it in '' if you wanna search more than one word, adn the 2nd parameter is the website you
# want to check
# I designed this one having in mind the need to produce small very informative messages to be 
# sent to a pager o cellphone where the screen real state is small. 
# I had to write it because the two available monitors with the same functionality, either
# hogged the CPU or the message output was useless for a pager o cellphone.
# Use it as you most like, and as usual don't blame me if this thing breaks up your box
#                                              Thanks, ElFarto elfarto at elfarto.com.ar


BASE_STR=`mcookie`
POS=11
LEN=8
prefix=checkmon
suffix=${BASE_STR:POS:LEN}
temp_filename=/tmp/$prefix.$suffix
if lynx --cookies --dump -connect_timeout=20 http://$2 >&$temp_filename;then 
    if cat $temp_filename | grep "$1" >/dev/null; then
	echo STATUS OK $MON_DESCRIPTION $2
	rm $temp_filename
        exit 0
        else
        echo $MON_DESCRIPTION $2
        echo "ERROR: STRING NOT FOUND"
    rm $temp_filename
    exit 1
    fi
else
    if cat $temp_filename | grep 'Unable to connect' >/dev/null; then
    echo $MON_DESCRIPTION $2
	echo "ERROR: Unable to Connect"
        rm $temp_filename
        exit 1
    else
        echo $MON_DESCRIPTION $2
        echo Unknown Error
        rm $temp_filename
        exit 1
    fi
    rm $temp_filename
fi