#!/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.txt"
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() {
( echo "Please find the patch log errors attached." ; uuencode "$OUTPUT_FILE" "$OUTPUT_FILE" ) | mailx -s "$EMAIL_SUBJECT" "$RECIPIENT"
}
# 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