Sponsored Content
Homework and Emergencies Homework & Coursework Questions monitor log entries and send e-mail Post 302426203 by vin8465 on Tuesday 1st of June 2010 07:01:17 AM
Old 06-01-2010
Error

Quote:
Originally Posted by Scrutinizer
Hi,

If I execute this statement on the command line, I get an error:
Code:
$ SEARCH='grep -i -E -q 'error|warning''
warning: command not found

You probably meant to use backticks (`) instead of quotes (')
This is sometimes difficult to see, that is why I prefer using $( ... ) instead of `...`
Also if you use grep you have give it something to grep (file or stdin)..

If you reference a variable you have to use a $-sign .
Code:
EMAILMESSAGE="$SCAN_LOG"

Thanks for pointing that out.
I also noticed that none of the commands like GREP that i defined have $ in front of them. I have corrected them. I will update the code and post it up again. Code someone please help me out with this.. I am finding it very confusing to do the script. Its the first time that i am writing such a script. I have hardly 3 months of experience and that too only by completing labs sheets of my uni.

---------- Post updated at 09:01 PM ---------- Previous update was at 08:15 PM ----------

I have made some improvements from the previous code and rectified the wrongs notified, thanks to

The code now execute without any error but gets stuck and i have to suspend the script manually. I am not able to figure out what the problem is and how am i supposed the implement the logic. Please see code below. I have tried to highlight all new lines of code that i have added:
Code:
#!/bin/sh -x
#
#
#
PRINTF=/usr/bin/printf
GREP=/usr/bin/grep
TAIL=/usr/bin/tail
COPY=/usr/bin/cp
CAT=/usr/bin/cat
LOG_FILE="$1"
LOG_PATH="/var/log/$1"

#To check if log file to check has been given as argument when running the script
if [ $# -ne 0 ] ; then
           $PRINTF "%s: Is the name of the log file you will be scanning. \n" $1
           $PRINTF $LOG_FILE"\n"
           $PRINTF $LOG_PATH"\n"

                if [ -f $LOG_PATH ];       #if logfile exits
                then
                        echo "File $LOG_FILE exists \n"
                        $COPY $LOG_PATH ./
                        $CAT -n $LOG_FILE > ./tmp_log
#                       $CAT tmp_log | less

                        #SEARCH=`GREP -i -E -q 'error|warning' $LOG_PATH` #search for strings error or warning in any form
                        # script to check for string to search
                        SEARCH=`$GREP -i 'error|warning'` #search for strings error or warning in any form
#                        SCAN_LOG=`$TAIL $1|[${SEARCH}]`  #scanning logfile for string pattern

                        # script to send simple email
                        SUBJECT="Error/Warning messages in logfile" # email subject
                        RECIPIENT="emailid@domain.extension" # Email To ?
#                       EMAILMESSAGE="$SCAN_LOG" # Email text/message
                        EMAILMESSAGE="$SEARCH" # Email text/message

                        /bin/mailx -s "$SUBJECT" "$RECIPIENT" < $EMAILMESSAGE # send an email using /bin/mail
                                echo "mail sent"
                else
                        echo "File $LOG_FILE does not exists \n"
                fi

        else
   $PRINTF "%s: Need the name of the log that needs to be checked\n" $0
#       EXIT (1)
fi

"logmon1" 48 lines, 1420 characters

The output is this:
Code:
> sh logmon1 log.03
log.03: Is the name of the log file you will be  scanning.
log.03
/../../log.03
File log.03 exists

^C
>

Just to add. I also do not receive any e-mail message. Some one please help me here with the logic also. The requirements of the script is highlighted in blue in the original post.
Thanks in advance!!!


I found another problem:
The below command when given in command line gives output if the word error is there in the file

Code:
grep - i 'error' <filename> 
Apr 26 03:40:55 goanna.cs.rmit.edu.au SRS Proxy[17590]: [ID 663108 daemon.error] Could not upload bulk message
Apr 26 03:45:56 goanna.cs.rmit.edu.au SRS Proxy[17590]: [ID 388765 daemon.error] Could not send message from queue: /var/SUNWsrspx/SRSQueueStore/store/queues/REGISTRATION/registration
Apr 26 03:49:11 goanna.cs.rmit.edu.au SRS Proxy[17590]: [ID 663108 daemon.error] Could not upload bulk message

But this gives no output even if the string are present in the file that is being searched
Code:
grep -i 'error|warning' <filename> 
>


Last edited by vin8465; 06-01-2010 at 08:28 AM.. Reason: Wanted to show how the program doesnt exit without manually exiting it "^C"
 

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

monitor log entries and send e-mail

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! I am stuck and worried. My assignment was due a day ago and I was too busy completing other assignments due during the same time. I worry that not completing this assignment... (1 Reply)
Discussion started by: vin8465
1 Replies

2. UNIX for Advanced & Expert Users

need to configure mail setting to send mail to outlook mail server

i have sun machines having solaris 9 & 10 OS . Now i need to send mail from the machines to my outlook account . I have the ip adress of OUTLOOK mail server. Now what are the setting i need to do in solaris machines so that i can use mailx or sendmail. actually i am trying to automate the high... (2 Replies)
Discussion started by: amitranjansahu
2 Replies

3. Shell Programming and Scripting

Monitor log file for a Error and generate the e-mail.

This is my log file and this is live log. Any abnormal error other than following I need to generate the email. Log path : /DER/app/admin/ABC/bdump/erg.log Current log# 2 seq# 103046 mem# 0: /ora2/oradata/ABC/redo02a.log Current log# 2 seq# 103046 mem# 1:... (1 Reply)
Discussion started by: hishanms
1 Replies

4. Shell Programming and Scripting

How to monitor log file for a Error and generate the e-mail ( Please help)

This is my log file and this is live log. Any abnormal error other than following I need to generate the email. Log path : /DER/app/admin/ABC/bdump/erg.log Current log# 2 seq# 103046 mem# 0: /ora2/oradata/ABC/redo02a.log Current log# 2 seq# 103046 mem# 1:... (7 Replies)
Discussion started by: hishanms
7 Replies

5. Shell Programming and Scripting

Looking for shell script to monitor CPU utilization and send mail once exceed 75%

Dear Group, I'm look for shell script to Monitor CPU usage and send mail once it exceed 75% I'm running Suse10.4. (3 Replies)
Discussion started by: clfever
3 Replies

6. Shell Programming and Scripting

Basic script for monitor send mail service

Hi All Need help Can any one share a basic script that is used for monitor sendmail service whether online, offline.etc in solaris Thanks in advance Zimmy (5 Replies)
Discussion started by: zimmyyash
5 Replies

7. Shell Programming and Scripting

Monitor file if match then send mail

Hi I want to monitor a file even if the file rotate. When a text occurs I want to send a mail. Something like this but it's not working correctly: tail -F mylog.log | grep 'MatchMe' | while read line do echo $(date +"%Y-%m-%d %H:%M:%S") MatchMe occurs | mail -s "MatchMe"... (1 Reply)
Discussion started by: chitech
1 Replies

8. Shell Programming and Scripting

Search the string in the active log and send mail

Hello, I wanted to search specific string in the acitve log file and send an email if the search string found in the log. Log file is written by application all the time. So, script has to search if any new log entry has the specific string for example " sample exception" and send an email. (1 Reply)
Discussion started by: balareddy
1 Replies

9. Shell Programming and Scripting

Monitor a file and send mail

I want to monitor the maillog file in real time and send a mail when a certain grep condition is met. Every time the grep condition is met a mail will be sent. I wish to ignore all grep conditions 30 mins after each mail and thereafter continue monitoring. For example: Condition is met, mail... (1 Reply)
Discussion started by: proactiveaditya
1 Replies

10. UNIX for Advanced & Expert Users

Client was not authenticated to send anonymous mail during MAIL FROM (in reply to MAIL FROM comm

I am having trouble getting mail to work on a red hat server. At first I was getting this message. Diagnostic-Code: X-Postfix; delivery temporarily suspended: connect to :25: Connection refused Then added the port to my firewall. Then I temporarily turned off selinux. I then copied this file... (1 Reply)
Discussion started by: cokedude
1 Replies
All times are GMT -4. The time now is 01:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy