help with script to send email and if subject line match is found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with script to send email and if subject line match is found
# 1  
Old 07-07-2010
help with script to send email and if subject line match is found

Help with script that will check log, then find a match is found, add that as the subject line.

1. The script will always run as a deamon.. and scan the event.log file
2. when a new 101 line is added to the event.log file, have the script check position 5,6 and 7 which is the job name, which is LOK
3. if position 5,6 and 7 is in a the hspm_table.txt then add the information on the right CGI CLAIMS in the email subject line of the email.

Event.log

Code:
 
101 WDC5337A 0AAAAAAAAAAAH54R NC_TLF2_SLEEP10 WDC5337A 1294422 5 NC_TLF2_SLEEP10 maestrot sleeep\0405400 -32768 1 2010070712140000 0 +++ 6453 1 1277734500 0 0 0 127 0AAAAAAAAAAAH54R 6453 TEST_JSA 2010062814150000 v.4 NONE NONE 4 NONE NONE NONE 0 0 0 0 0 NONE
101 LILTST505 0AAAAAAAAAAAHXH2 CU_MLOK_IAM_INTAKE_PROCESS_LILVSGT4W LILVSGT4W 558803 5 CU_MLOK_IAM_INTAKE_PROCESS_LILVSGT4W silver\REED_APP e:\FMLA\CIGNA_CGI_Intake_Processor.BAT 0015 10 2010070712300000 0 +++ 7748 1 1278505800 0 60 0 1 0AAAAAAAAAAAHXH2 5973 MLOKIAM1 2010070612110000 v.4 NONE NONE 4 NONE NONE NONE 0 0 0 0 0 NONE



hspm_table.txt

Code:
 
LF2 PROD CNTL ADMIN SERV
LKB PROD SVC DB2 DBA
LKG PROD SVC DB2 DBA
LKJ AMP CGI AQUISITION
LOK CGI CLAIMS


Here is my script that only sends the email, but does not check the hspm_table.txt to find a match.

Code:
 
#!/bin/sh -x 
DATE=`date` 
TWSHOME=/usr/lib/maestro/ 
EVENTLOG=event.log 
MAILING="email@fromtable" 
tail -f -n 1 $TWSHOME/$EVENTLOG | while read line ; do echo "$line" | grep '^101' ; if [ $? -eq 0 ]; then echo "$line" | awk '{print "Mail sent by checkevent.sh script""\n""\n""A Job has abended.""\n""Please check information below:""\n""Workstation:",$2,"\n""Job Stream:",$3,"\n""Job Name:",$4"\n""Job ID:",$6,"\n""Job Status:",$7,"\n""Scheduled Time:",$26,"\n""Actual Start:",$13"\n""\n""Thanks""\n""TWS team."}' | mail -s "Email sent from `hostname` at $DATE" $MAILING ; fi ; done

# 2  
Old 07-07-2010
How is the script to know which events have already been reported?
The back slashes in the data could also be problematic.
# 3  
Old 07-07-2010
Quote:
Originally Posted by jgt
How is the script to know which events have already been reported?
The back slashes in the data could also be problematic.
good point... this is why im here.. in hopes of finding a better way of scripting it..

here is an example of the email sent.

Code:
 
Mail sent by checkevent.sh script
A Job has abended.
Please check information below:
Workstation: LILTST505
Job Stream: 0AAAAAAAAAAAHXH3
Job Name: CU_MLOK_IAM_INTAKE_PROCESS_LILVSGT4W
Job ID: 558869
Job Status: 5
Scheduled Time: 2010070712110000
Actual Start: 2010070715450000
Thanks
TWS team.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Modify text file if found multiple pattern match for every line.

Looking for help, i have input file like below and want to modify to expected output, if can without create additional file, hope can direct modify it. have 2 thing need do. 1st is adding a word (testplan generation off) after ! ! IPG: Tue Aug 07 14:31:17 2018 2nd is adding... (16 Replies)
Discussion started by: kttan
16 Replies

2. Shell Programming and Scripting

Add comment on last line if found match

Hi All, totally new on it , normally use it for just 1 line. i'm looking for help. i'm have 2 file. file 1 : -------------------------------------------------- c12 c1 c3 -------------------------------------------------- file 2: other content ... (10 Replies)
Discussion started by: kttan
10 Replies

3. Shell Programming and Scripting

Sendemail how to send an email with a subject variable

Hi,:) I try this : #!/bin/bash sender="me@example.com" recipient="you@example.com" subject="TEST FILE" server="0.0.0.0" file=$(cat file.txt) /usr/bin/sendemail -f $sender -t $recipient -u $subject -m $file My file.txt: BLABLALA BLABLABLA (7 Replies)
Discussion started by: Arnaudh78
7 Replies

4. Shell Programming and Scripting

How to print the entire line if the mentioned match is found?

Hello Everyone, I have a file with 5 fields in each line just like mentioned below. Also the 4th field is time elapsed(hh:mm:ss) since the process is running xyz abc status 23:00:00 idle abc def status 24:00:00 idle def gji status 27:00:02 idle fgh gty status 00:00:00 idle Here I... (8 Replies)
Discussion started by: rahul2662
8 Replies

5. Shell Programming and Scripting

Displaying text till pattern match found in a line

Hi All, From the below line if we want to display all the text till found pattern dot/. I was trying with the below code but couldn't able to print text before the pattern. it display texts which is found after pattern. awk '/assed/{print;getline;print}' file_name | sed 's/^*. *//' input... (4 Replies)
Discussion started by: Optimus81
4 Replies

6. UNIX for Dummies Questions & Answers

Display n lines after match found and other line

I have a file like this DoctorName Address1 Address2 DOB InsuredName Address1 Address2 DOB PatientName Address1 Address2 DOB ClaimNo1 DoctorName Address1 Address2 DOB InsuredName (2 Replies)
Discussion started by: nsuresh316
2 Replies

7. Shell Programming and Scripting

How to read specific line of text from a Script and send email notification

Hi ! I am a newbie and never officially wrote a shell script before. The requirement for this script is : 1) Read a file called 'bpm.log' and identify if it has a specific text such as 'this is the text'. Its a static value and that is the only text we need to read. 2) If that... (2 Replies)
Discussion started by: atechcorp
2 Replies

8. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

9. Shell Programming and Scripting

Run a script based on the subject line of the email

Hi, I need help in running a script that would pull info from an email subject line and run a script (foo.sh). I'm pretty sure after a bit of googling that this is possible in several ways. but none was pretty clear on how to accomplish it. The part that I really need help with is getting the... (5 Replies)
Discussion started by: satekn
5 Replies

10. Shell Programming and Scripting

if match found go to a particular line in perl

Hello Experts, I am newbie to perl, just curious to know how to do the following in perl. suppose I ve a txt file like below. when it founds "*Main Start" Then go to "*Main End,,,,,,,," patteren and just collect the number from the previous line of "*Main End,,,,,,," pattern . In my... (17 Replies)
Discussion started by: user_prady
17 Replies
Login or Register to Ask a Question