Bash to check for 404 Errors (with records)

#Start infinite Loop

for (( ; ; ))
do

#Check the Newest File in same director as Script

NEWESTFILE=`ls -tr | tail -1`

#Start Wireshark on Port 80 & Port 443, check for Request & Response coming on these ports, select interface WLAN0 and do this for 15 seconds, print output to
#Text file with name as Date & Time Stamp

sudo tshark tcp port 80 or tcp port 443 -V -R “http.request || http.response” -i wlan0 -T ps -a duration:15 > $(date “+%b_%d_%Y_%H.%M.%S”).txt

#Display latest file name

echo $NEWESTFILE

#Check for 404 Not Found error in latest output file, if found send Email with body “Mail Sent”, Subject “Error” and to the recepient pointed.out@gmail.com
#

if grep -F “404 Not Found” $NEWESTFILE;
then
echo “Error Found”
#echo $NEWESTFILE | mail -s “Error” -a $NEWESTFILE pointed.out@gmail.com
echo $NEWESTFILE | mutt  -a $NEWESTFILE -s “Error” — pointed.out@gmail.com
else
echo “No Error”
 fi
sleep 1
done

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.