Script to search for errors in the logs of all the JVM and send mail

  the script to search for errors in the logs of all the JVMs. Here's an example of how you can modify the script:



#!/bin/bash


# Set the path to the logs directory

LOGS_DIR="/logs/servers"


# Set the email address to send notifications to

EMAIL_ADDRESS="user@example.com"


# Search the logs directory for SystemOut.log files and check for errors

for log_file in $(find $LOGS_DIR -name "SystemOut.log"); do

  # Search the log file for errors

  ERRORS=$(grep -E "(ERROR|FATAL)" $log_file)


  # If errors are found, send an email notification

  if [ -n "$ERRORS" ]; then

    echo "$ERRORS" | mail -s "Error found in WebSphere SystemOut.log for $log_file" $EMAIL_ADDRESS

  fi

done


Save the above script to a file, for example, check_websphere_logs.sh and make it executable using the chmod command:

chmod +x check_websphere_logs.sh

To run the script, simply execute it from the command line:


./check_websphere_logs.sh


The script will search for all the SystemOut.log files in the specified logs directory and check for any lines containing the words "ERROR" or "FATAL". If any errors are found in a log file, the script will send an email notification to the specified email address, indicating which log file contains the error.


Note that this script will search for errors in all the SystemOut.log files in the logs directory, including those of different JVMs or instances. If you want to search for errors in a specific JVM or instance, you can modify the script to only search for logs in that directory.

Comments

Popular posts from this blog

Shell script to find out aliases and their expiration in cacerts

shell script to scp multiple file to multiple destinations

How to resolve port conflict in websphere