Bash to check for 404 Errors (with records)

#Start infinite Loop

for (( ; ; ))

#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


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

if grep -F “404 Not Found” $NEWESTFILE;
echo “Error Found”
#echo $NEWESTFILE | mail -s “Error” -a $NEWESTFILE
echo $NEWESTFILE | mutt  -a $NEWESTFILE -s “Error” —
echo “No Error”
sleep 1


Leave a Reply

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

You are commenting using your 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.