Sponsored Content
Top Forums Shell Programming and Scripting help with script to send email and if subject line match is found Post 302435537 by axdelg on Wednesday 7th of July 2010 03:23:23 PM
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

 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
TRUNCATE(1)                                                        User Commands                                                       TRUNCATE(1)

NAME
truncate - shrink or extend the size of a file to the specified size SYNOPSIS
truncate OPTION... FILE... DESCRIPTION
Shrink or extend the size of each FILE to the specified size A FILE argument that does not exist is created. If a FILE is larger than the specified size, the extra data is lost. If a FILE is shorter, it is extended and the extended part (hole) reads as zero bytes. Mandatory arguments to long options are mandatory for short options too. -c, --no-create do not create any files -o, --io-blocks treat SIZE as number of IO blocks instead of bytes -r, --reference=RFILE base size on RFILE -s, --size=SIZE set or adjust the file size by SIZE bytes --help display this help and exit --version output version information and exit The SIZE argument is an integer and optional unit (example: 10K is 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (pow- ers of 1000). SIZE may also be prefixed by one of the following modifying characters: '+' extend by, '-' reduce by, '<' at most, '>' at least, '/' round down to multiple of, '%' round up to multiple of. AUTHOR
Written by Padraig Brady. REPORTING BUGS
GNU coreutils online help: <http://www.gnu.org/software/coreutils/> Report truncate translation bugs to <http://translationproject.org/team/> COPYRIGHT
Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
dd(1), truncate(2), ftruncate(2) Full documentation at: <http://www.gnu.org/software/coreutils/truncate> or available locally via: info '(coreutils) truncate invocation' GNU coreutils 8.28 January 2018 TRUNCATE(1)
All times are GMT -4. The time now is 05:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy