LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-28-2014, 05:57 AM   #16
Lachhman
LQ Newbie
 
Registered: Dec 2014
Posts: 3

Rep: Reputation: Disabled

have a look at script i want to add multiple error in "ALERT" Variable but getting error nor getting required result.when im writing only one error then script is running successfully.Kindly suggest me how i add multiple error in this script as i can get required result.
For single hard code error like ALERT="ORA-00060" it working perfect.

Thanks in advance.



#!/bin/sh

#GLOBS
ALERT="ORA-00060","TNS","crash","Error",'abort","cannot allocate","not complete","waiting","All online" ;
LOGFILE=/path/to/my/alert_X.log
MYFILE=/home/user/test.log
##


#get the errors out of the logfile.
grep -h "$ALERT" $LOGFILE >> $MYFILE

#count number of lines in myfile, and print.
VAR=`wc -l $MYFILE | awk -F" " '{print $1}'`
#echo $VAR



# if the amount of lines is greater than 0, then cat the file and send it to me. if not then echo all clear.

#size variable is the number of errors the last time the script ran

size=`wc -l test.last | awk -F" " '{print $1}'`
echo $size

# if the amount of lines is greater than 0, then cat the file and send it to me. if not then echo all clear

if [[ $VAR -gt $size ]] ; then

cat $MYFILE | mail -vs "oralert" user@domain.com ;

else
echo "All clear.."


fi;

rm test.last
mv test.log test.last
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 12-28-2014, 05:59 AM   #17
Lachhman
LQ Newbie
 
Registered: Dec 2014
Posts: 3

Rep: Reputation: Disabled
Please suggest me how to add diff critical error in this script.
here in this script u have only defined one ALERT="ORA-00060"; .I tried to add multiple error as same type of error came in my alert log so i can easily rectify ASAP.Kindly help me add multiple ora error nhn with ALERT="ORA-00060";
Thanks in Advance
 
Old 12-28-2014, 06:27 AM   #18
unSpawn
Moderator
 
Registered: May 2001
Posts: 28,510
Blog Entries: 55

Rep: Reputation: 3270Reputation: 3270Reputation: 3270Reputation: 3270Reputation: 3270Reputation: 3270Reputation: 3270Reputation: 3270Reputation: 3270Reputation: 3270Reputation: 3270
While English may not be your first language you must realize that just repeating your question isn't going to solve things.

It should look something like this:
Code:
#!/bin/sh --
# Unset debug mode when done testing:
set -Cvxe
# Set default behaviour:
LANG=C; LC_ALL=C; export LANG LC_ALL
# The alert codes to look for:
ALERTS="ORA-00060|ORA-00061|ORA-00062";
# The log file and location:
LOGFILE=/path/to/my/alert_X.log
# The email address to report to:
EMAILADDR="email@domain.com"

# Use a temporary directory to hold temporary files:
export TMPDIR=/tmp; _MYTMPDIR=`mktemp -p "${TMPDIR}" -d ${oralert}.XXXXXXXXXX` && {
 # Get the errors out of the logfile:
 egrep -h "($ALERT)" "${LOGFILE}" > "${_MYTMPDIR}/tempfile" 2>/dev/null;
 # Count number of lines:
 LINECOUNT=$(wc -l "${_MYTMPDIR}/tempfile" 2>/dev/null|awk -F" " '{print $1}')
 # If the amount of lines is greater than 0, then cat the file and send it. 
 # If not then clean up and exit cleanly.
 [ ${LINECOUNT} -gt 0 ] && { cat "${_MYTMPDIR}/tempfile"|mail -vs "oralert" "${EMAILADDR}"; }
 } # End Mktemp
rm -rf "${_MYTMPDIR}" || exit 127
exit 0
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SSH Alert when root attempts to log gamehack Linux - Software 3 06-03-2009 06:44 AM
Shutdown script possible to alert about connected USB devices? Roy Prins Linux - Newbie 6 07-23-2008 06:47 AM
Oracle 9i Alert logs cmontr Linux - General 3 12-11-2007 05:21 PM
Shell script for password expiry alert bhandu Linux - General 1 06-13-2007 04:19 AM
snort not logging port scans? Should I use log or alert? lucastic Linux - Security 3 08-30-2004 04:34 AM


All times are GMT -5. The time now is 11:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration