Thursday, August 3, 2023

Scan patches

 #!/bin/sh


# Define variables

APPL_TOP="/path/to/APPL_TOP"

TWO_TASK="your_TWO_TASK_value"

LOG_DIR="$APPL_TOP/admin/$TWO_TASK/log"

OUTPUT_FILE="patch_errors.txt"

RECIPIENT="user@example.com"

EMAIL_SUBJECT="Patch Log Errors"


# Function to find the most recent patch log files

get_recent_log_files() {

    find "$LOG_DIR" -name "*.log" -o -name "*.lgi" -type f -exec stat -c "%Y %n" {} + | sort -r | head -n 1 | cut -d ' ' -f 2-

}


# Function to scan log files for errors, warnings, and failures

scan_log_files() {

    grep -E -i "error|warning|failed" $(get_recent_log_files) > $OUTPUT_FILE

}


# Send email function

send_email() {

    cat $OUTPUT_FILE | mailx -s "$EMAIL_SUBJECT" "$RECIPIENT"

}


# Main script execution

recent_log_files=$(get_recent_log_files)

if [ -n "$recent_log_files" ]; then

    scan_log_files

    if [ -s "$OUTPUT_FILE" ]; then

        send_email

        echo "Email sent with the error details from the most recent patch log."

    else

        echo "No errors, warnings, or failures found in the most recent patch log."

    fi

else

    echo "No patch log files found in the specified location."

fi


No comments:

Post a Comment