#!/usr/bin/ksh
# Script version
SCRIPT_VERSION="v1.0"
# Check if both log file location and name are provided as arguments
if [ $# -ne 2 ]; then
echo "Usage: $0 <log_file_location> <log_file_name>"
exit 1
fi
# Set the input parameters to variables
LOG_FILE_LOCATION="$1"
LOG_FILE_NAME="$2"
# Define other variables
OUTPUT_FILE="patch_errors.html"
RECIPIENT="user@example.com"
EMAIL_SUBJECT="Patch Log Errors - $LOG_FILE_NAME"
# Function to scan log files for errors, warnings, and failures
scan_log_files() {
egrep -i "error|warning|failed" "$LOG_FILE_LOCATION/$LOG_FILE_NAME" > "$OUTPUT_FILE"
}
# Function to send email with the output in the email body
send_email() {
email_body="<p>Please find the patch log errors below:</p><pre>"
# Append each line to the email body content with <br> tag for new lines
while IFS= read -r line; do
email_body+="$line<br>"
done < "$OUTPUT_FILE"
email_body+="</pre>"
# Send the email with the email body content
echo "Content-Type: text/html" | mailx -s "$EMAIL_SUBJECT" "$RECIPIENT" -M "text/html" <<< "$email_body"
# Clean up the temporary file
rm "$OUTPUT_FILE"
}
# Main script execution
scan_log_files
if [ -s "$OUTPUT_FILE" ]; then
send_email
echo "Email sent with the error details from the log file: $LOG_FILE_NAME."
else
echo "No errors, warnings, or failures found in the log file: $LOG_FILE_NAME."
fi
# Display script version
echo "Script version: $SCRIPT_VERSION"
No comments:
Post a Comment