Thursday, August 3, 2023

latest

 #!/usr/bin/ksh


# 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 file as attachment

send_email() {

    email_body="<p>Please find the patch log errors in the attachment.</p>"

    email_file="email_content.html"

    

    # Create the email content file with HTML tags

    {

        echo "<html>"

        echo "<body>"

        echo "$email_body"

        echo "</body>"

        echo "</html>"

    } > "$email_file"


    # Send the email with the HTML content file as attachment

    ( echo "Content-Type: text/html" ; uuencode "$OUTPUT_FILE" "$OUTPUT_FILE" ; uuencode "$email_file" "$email_file" ) | mailx -s "$EMAIL_SUBJECT" "$RECIPIENT"


    # Clean up the temporary files

    rm "$OUTPUT_FILE" "$email_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


No comments:

Post a Comment