monitor log entries and send e-mail


 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support monitor log entries and send e-mail
# 1  
Old 05-31-2010
Error 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 will fail me. Need urgent help in completing the script asap. I dont want to sound pushy to get the answer but just wanted to explain the situation.

1. The problem statement, all variables and given/known data:

I have mentioned a detailed requirement to be very clear. The points with '*' are the tasks that the script is
expected to do. All other information provided is for clear understanding of the script functionality.

The basic form of the script will simply send a copy of all lines that contain either "error" or "warning"
to the user specified in the script as RECIPIENT. Note that RECIPIENT is a shell variable that will contain
an e-mail address.
The basic script will be able to look at a log file periodically and report on any new lines that contain
either "error" or "warning". The search for this text is to be "case insensitive". This means that the script
needs to accept a line containing either "error", "Error", "ERROR" or the word error spelt in any other
combination of upper and lower case letters as being functionally equivalent.

The basic script, named "logmon" (for log monitor) will need to do the following:

* be able to run in an environment that does not include a path. (i.e. the environment provided by
cron)

* accept the name of a log file as the sole command line argument
* search the specified log file for lines that have been added since the previous search.
* construct an e-mail reporting any lines that contain either "error" or "warning" in any combination
of upper and lower case letters
* send the e-mail to the address specified in the RECIPIENT shell variable which is defined within the
script

Optional requirements for now
Include only putting a single copy of a message in an e-mail, but reporting
how many times the message is repeated. Also modifying the script so that the same script will either
report via e-mail, or directly to a terminal, depending on how it is called. The final option will
be a system that reports errors directly to the root console.
(Note that this will need to be implemented in a way that sends the message to your account and does not actually send a message to root for testing purpose.)

Please add a comment or comments in your script that state which, if any, of the optional requirements have been implemented.

* modify the script so that, instead of listing multiple lines with the same message, it lists one instance
of each duplicated line (Note that for the purposes of this requirement, two lines that share everything
except the timestamp are considered to be identical lines.)

* follows the single instance of a duplicated line with a line that reports how many times the previous
line repeats

* add code that will report the above to the command line when it is called with the name "logcheck"
(How could you have one script that has two different names?)


Note that any data that needs to be passed from one time when the script runs to the next time cannot be passed in a temporary file. It will
need to be stored in a secure location.

Certain commands that I thought might be helpful are diff, wc, tail, grep, awk, and sort. Can anyone think of a way to do the above. Any suggestions
are most welcome.
Thanks in Advance for all the help.


2. Relevant commands, code, scripts, algorithms:



Algorithm of the program that I have come up with
Step1: Enter Logname(name of log file) as argument when running script
Step2: Check if argument is given, if not then exit with error else check for filename
Step3: If filename given as argument does not exists, exit with error else check for search string pattern in log file
Step4: if string pattern found then copy log entry to a variable and temp file
Step5: Check for similar log entries ignoring date stamp
Step6: if similar log entry found, increment counter
Step7: if currently running script name is logmon then send email else send message to current terminal

3. The attempts at a solution (include all code and scripts):

#!/bin/sh -x
#
#
#
PRINTF=/usr/bin/printf
GREP=/usr/bin/grep
TAIL=/usr/bin/tail
#To if log file to check has been given as argument when running the script
if [ $# -eq 0 ] ; then
$PRINTF "%s: Need the name of the log that needs to be checked\n" $0
$PRINTF $0 "\tis the name of the script you are running" #Just to display what is the script name
$PRINTF $1 "\tis the name of the log file you want to scan" #Just to display what is the argument
exit 1
fi
# script to send simple email
SUBJECT="Enter Subject Here" # email subject
RECIPIENT="yourmailid@domain.com" # Email To ?
EMAILMESSAGE="My test script" # Email text/message

/bin/mailx -s "$SUBJECT" "$RECIPIENT" < $EMAILMESSAGE # send an email using /bin/mail

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



#Keep track of similar entries
MESSAGE_COUNTER=0
MESSAGE="$LOG_ENTRY"


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
RMIT University, Melbourne,Australia,Don,http://www.rmit.edu.au/courses/039989

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

---------- Post updated at 10:37 AM ---------- Previous update was at 10:11 AM ----------

The log file structure looks like below

Apr 26 03:18:54 goanna.cs.rmit.edu.au SRS Proxy[17590]: [ID 663108 daemon.error] Could not upload bulk message
Apr 26 03:21:25 goanna.cs.rmit.edu.au last message repeated 3 times
Apr 26 03:31:41 goanna.cs.rmit.edu.au puppetd[25496]: [ID 702911 daemon.notice] (//Node[server_base]/pca/File[/opt/isunix/output]) Dependency file[/var/tmp/patchdiag.xref] has 1 failures
Apr 26 03:31:41 goanna.cs.rmit.edu.au puppetd[25496]: [ID 702911 daemon.warning] (//Node[server_base]/pca/File[/opt/isunix/output]) Skipping because of failed dependencies
Apr 26 03:31:41 goanna.cs.rmit.edu.au puppetd[25496]: [ID 702911 daemon.notice] Finished catalog run in 134.93 seconds
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:44:40 goanna.cs.rmit.edu.au last message repeated 3 times
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
Apr 26 03:52:52 goanna.cs.rmit.edu.au SRS Proxy[17590]: [ID 601329 daemon.warning] QueueStore reclaimed 1 entry, 6144 bytes
Apr 26 04:05:59 goanna.cs.rmit.edu.au puppetd[25496]: [ID 702911 daemon.warning] (//Node[server_base]/pca/Exec[pca-generate-missingrs]) Skipping because of failed dependencies
Apr 26 04:05:59 goanna.cs.rmit.edu.au puppetd[25496]: [ID 702911 daemon.notice] (//Node[server_base]/pca/File[/opt/isunix/output]) Dependency file[/var/tmp/patchdiag.xref] has 1 failures
Apr 26 04:05:59 goanna.cs.rmit.edu.au puppetd[25496]: [ID 702911 daemon.warning] (//Node[server_base]/pca/File[/opt/isunix/output]) Skipping because of failed dependencies
Apr 26 04:06:00 goanna.cs.rmit.edu.au puppetd[25496]: [ID 702911 daemon.notice] Finished catalog run in 135.37 seconds
Apr 26 04:06:41 goanna.cs.rmit.edu.au SRS Proxy[17590]: [ID 663108 daemon.error] Could not upload bulk message
Apr 26 04:07: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 04:11:11 goanna.cs.rmit.edu.au SRS Proxy[17590]: [ID 663108 daemon.error] Could not upload bulk message
Apr 26 04:22:56 goanna.cs.rmit.edu.au SRS Proxy[17590]: [ID 663108 daemon.error] Could not upload bulk message
Apr 26 04:25:26 goanna.cs.rmit.edu.au last message repeated 2 times
# 2  
Old 06-01-2010
Double post, continued here, thread closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. Homework & Coursework Questions

monitor log entries and send e-mail

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 will fail me. Need urgent help in completing the script asap. I dont want to sound pushy to get the answer but just wanted to... (10 Replies)
Discussion started by: vin8465
10 Replies
Login or Register to Ask a Question