Last active
December 16, 2017 04:12
-
-
Save rav94/b5dc5c76e3254f660fa1cd4e2bd397a6 to your computer and use it in GitHub Desktop.
Shell script for reporting nohup.out general errors into specified email/s.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Check whether a temporary file exisits | |
if [ ! -e nohup_errors_log ]; | |
#If not you are here | |
then | |
#Grep for the desired pattern within your log file to catch the Error and Save the content to a new temporary file | |
grep "\[[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\},[0-9]\{3\}\] ERROR" /home/ubuntu/ravindu/nohup.out | sort > nohup_errors_log | |
#Mail the recorded error list to the desired mail (You can mail it to multiple uses also) | |
mail -s "Error Log for nohup.out" [email protected] < nohup_errors_log | |
else | |
#Compare the difference between the nohup.out file and the content within the temporry file and only mail send me a mail only when ther s an error | |
comm -23 <(grep "\[[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\},[0-9]\{3\}\] ERROR" /home/ubuntu/ravindu/nohup.out | sort) nohup_errors_log | mail --exec 'set nonullbody' -s "Error Log for nohup.out" [email protected] | |
#Add the new content into our temporary file | |
grep "\[[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\},[0-9]\{3\}\] ERROR" /home/ubuntu/ravindu/nohup.out | sort > nohup_errors_log | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment