script to check error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to check error
# 1  
Old 11-27-2007
script to check error

I have below script to check the word in the driectory /ora_tmp , there are many files in this directory , if the word "error" is exist in any file within 5 day , then send the mail to ora-usr@mydomain.com about which file have this word and the "error" statement , now , if I want

1. if there is no "error" word existed in any file , then DO NOT send the mail ;
2. send "error" statement to user one time only , that mean , only inform user the "error" statement one time , if there are same "error" statement within 5 days , send the mail to user one time only ( the user need to know the same error one time only ) . can advise how can I change it ? thx.

FILE=/tmp/error ; export FILE


mailfile=/tmp/mailfile ; export mailfile


find /ora_tmp -type f -mtime -5 -maxdepth 1 | xargs grep -i "error" > $FILE

cat $FILE >> $mailfile

echo $mailfile
mail ora-usr@mydomain.com < $mailfile
# 2  
Old 11-28-2007
Hi ust,

find /ora_tmp -type f -mtime -5 -maxdepth 1 | xargs grep -i "error" > $FILE

After this, check the size of the file using test command

if [ -s $FILE ] then
#FILE exists and has a size greater than zero
# To send the mail only once use sort and uniq commands
sort $FILE | uniq >> $mailfile
mail ora-usr@mydomain.com < $mailfile

else
# Do nothing(which means there is no error)
fi

Hope this will give you some idea to proceed!Smilie

Regards,
Chella
# 3  
Old 12-10-2007
thx reply ,

I modified the script as below , it can send nodify mail only when there is error ,
but I am not too understand the suggestion above , my requirement is " to send "error" statement to user one time only , that mean , only inform user the "error" statement one time , if there are same "error" statement within 5 days , send the mail to user one time only ( the user need to know the same error one time only ) . can advise ? thx


FILE=/tmp/error ; export FILE
mailfile=/tmp/mailfile ; export mailfile
find /ora_tmp -type f -mtime -5 -maxdepth 1 | xargs grep -i "error" > $FILE
if [ -s $FILE ] ; then
cat $FILE >> $mailfile
echo $mailfile
mail ora-usr@mydomain.com < $mailfile
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk script to check and throw error for multiplication result

I need to multiply column1 and column3 data and need to compare it with column5. Need to check multiplication and Throw error if result is greater or less than column5 values, though difference of +/- 2 will be ok Ex - if column1 has 2.4 and column3 has 3.5, it will be ok if column5 have value... (13 Replies)
Discussion started by: as7951
13 Replies

2. Shell Programming and Scripting

Bash shell script to check if script itself is running

hi guys we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies

3. Shell Programming and Scripting

Shell script that check the argument passed to it and prints error if test condition is not met

I want to make a script that check for the argument passed to it and generates an error in case any character/string argument passed to it. I am using below code, but its not working. can anyone help. #!/bin/bash if ]; then echo 'An integer argument is passed to the script hence... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

4. Shell Programming and Scripting

script to check if another script is running and if so, then sleep for sometime and check again

Hi, I am a unix newbie. I need to write a script to check wheteher another script is still running. If it is, then sleep for 30m and then check again if the script is running. If the script has stopped running then, I need to come out of the loop. I am using RHEL 5.2 (2 Replies)
Discussion started by: mathews
2 Replies

5. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

6. Shell Programming and Scripting

how to check which line of the script is showing the error

how to check which line of the script is showing the error... like -x will print each output in stdout... but want to know exact error line trowing error.. (2 Replies)
Discussion started by: mail2sant
2 Replies

7. Shell Programming and Scripting

Check Error On Script

If I have a script createdb.sh ... psql -U postgres -c "create database dbname" ... I want to write something like if IsErr(psql -U postgres -c "create database dbname") ehco "OK" else ehco "NOT OK" Thank for any reply first (3 Replies)
Discussion started by: uativan
3 Replies

8. Shell Programming and Scripting

check in unix shell script so that no one is able to run the script manually

I want to create an automated script which is called by another maually executed script. The condition is that the no one should be able to manually execute the automated script. The automated script can be on the same machine or it can be on a remote machine. Can any one suggest a check in the... (1 Reply)
Discussion started by: adi_bang76
1 Replies

9. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies
Login or Register to Ask a Question