Script to only email new record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to only email new record
# 1  
Old 05-25-2012
Script to only email new record

Hello,

I'm trying to monitor queues for specific tickets and email the user only when a new ticket is created.

But to complicate things, I need to think how I'm going to deal with repeat emails on the same ticket until it is closed.

Meaning, script runs every 15 minutes, if it finds a ticket and report on it, then the next 15 minutes it will report the same ticket and I don't want that.

The script itself is functioning Smilie, as in ... sqlplus query finds tickets and the script emails them however, it emails all the tickets and only want to see the ticket that was create in the last 15 mins.

really confused ... or I'm going about this wrong way .....

My sqlplus query is

Code:
-- Query output formatting

  SET HEADING ON
  SET FEEDBACK OFF
  SET PAGESIZE 0
  SET LINESIZE 500

-- This is the actual query

  SELECT TICKET_NUMBER,
         QID,
         TO_CHAR (RCD, 'DD-MON-YYYY HH24:MI:SS'),
         TO_CHAR (AP_DATE, 'DD-MON-YYYY HH24:MI:SS'),
         CCT,
         CUSTOMER
    FROM VT_TR
   WHERE cct like 'L1L%' and qid in ('D', 'E', 'F','S', 'Z')
      or cct like 'L2L%' and qid in ('D', 'E', 'F','S', 'Z')
     AND (RCD) > RCD -15/(24*60)
   ORDER by rcd;
    exit;

and the AWK code is ...

Code:
    awk '{print "Ticket #: " $1}
         {print "Queue : " $2}
         {print "Recieved Date : " $3}
         {print "Recieved Time : " $4}
         {print "AP Date : " $5}
         {print "AP Time : " $6}
         {print "Circuit ID : " $7}
         {print "Customer Name : " $8, $9, $10, $11 "\n"}' $FBLOG >$FBLOG.1


Any assistance is greatly appreciated ...

thank you in advance
# 2  
Old 05-25-2012
Change your query so the 'cct' and 'qid' selection is done as one condition so if that condition is meet and then the date condition is meet, the data is selected:
Code:
select ticket_number, qid, to_char( rcd, 'dd-mon-yyyy hh24:mi:ss' ) as rcd,
       to_char( ap_date, 'dd-mon-yyyy hh24:mi:ss' ) as ap_date, cct, customer
 from  vt_tr
where  ( ( cct like 'L1L%'
  or       cct like 'L2L%' )
 and       qid in( 'D', 'E', 'F','S', 'Z' ) )
 and   rcd  >  rcd - interval '15' minute
order by rcd;

Your current query is only looking at date selection for the 'or' cct selection:
Code:
WHERE cct like 'L1L%' and qid in ('D', 'E', 'F','S', 'Z')
or cct like 'L2L%' and qid in ('D', 'E', 'F','S', 'Z')
AND (RCD) > RCD -15/(24*60)

# 3  
Old 05-28-2012
Good morning Spacebar,

Thank you for the reply ...

Your query does make more sense ...thank you very much, however the results are still same as in that the script emails all of the tickets and not just the newest one ...

I'm wondering if I have cat the log file to see if the was previously listed and if not then email if yes then send no email ...

I hope I'm making sense .....
# 4  
Old 05-28-2012
Better to add a flag column to database to identify which all have not been sent. While you send the emails, store the primary key in some temp file. Then after sending mails, update the flag column of database using that temp file.

While retrieving data from table check the condition on flag column.
# 5  
Old 05-28-2012
As donadarsh said you could add a column(sent) to your table and just update it to a 'Y' or '1' when row has been sent.
You would then change your sql to only select rows that have not been sent:
select ticket_number, qid, to_char( rcd, 'dd-mon-yyyy hh24:mi:ss' ) as rcd, to_char( ap_date, 'dd-mon-yyyy hh24:mi:ss' ) as ap_date, cct, customer from vt_tr where sent != 'Y' -- Or a '1' if you deceide to use 0 and 1 order by rcd;
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need code for updating second record to first record in shell scripting

Hi,, I have requirement that i need to get DISTINCT values from a table and if there are two records i need to update it to one record and then need to submit INSERT statements by using the updated value as a parameter. Here is the example follows.. SELECT DISTINCT ID FROM OFFER_GROUP WHERE... (1 Reply)
Discussion started by: Samah
1 Replies

2. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

3. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

4. Shell Programming and Scripting

Reject the record if the record in the next line does not begin with 2.

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten 2eleven 2twelve 1thirteen 2fourteen The output should be: (5 Replies)
Discussion started by: supchand
5 Replies

5. Shell Programming and Scripting

Reject the record if the record in the next line does not satisfy the pattern

Hi, I have a input file with the following entries: 1one 2two 3three 1four 2five 3six 1seven 1eight 1nine 2ten The output should be 1one 2two 3three 1four 2five 3six (2 Replies)
Discussion started by: supchand
2 Replies

6. Shell Programming and Scripting

Script to extract particular record

Hi, I have a large file with huge number of records which are of following pattern: TYPE1 { originNodeType : "IVR" originHostName : "AAIVR" originTransactionID : "01310559" originTimeStamp : "20110620192440+0530" hostName : "hhhh" voucher : '0'D rProfileID : "ZZZZ" Before { Flags :... (1 Reply)
Discussion started by: madhukar1anand
1 Replies

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

8. UNIX for Dummies Questions & Answers

how to read record by record from a file in unix

Hi guys, i have a big file with the following format.This includes header(H),detail(D) and trailer(T) information in the file.My problem is i have to search for the character "6h" at 14 th and 15 th position in all the records .if it is there i have to write all those records into a... (1 Reply)
Discussion started by: raoscb
1 Replies

9. Shell Programming and Scripting

Script to search a bad record in a file then put the record in the bad file

I need to write a script that can find a bad record (for example: there is date field colom but value provided in the file for this field is N/A) then script shoud searches this pattern and then insert the whole record into the bad file. Example: File1 Name designation dateOfJoining... (2 Replies)
Discussion started by: shilendrajadon
2 Replies

10. UNIX for Advanced & Expert Users

Script to search a bad record in a file then put the record in the bad file

I need to write a script that can find a bad record (for example: there is date field colom but value provided in the file for this field is N/A) then script shoud searches this pattern and then insert the whole record into the bad file. Example: File1 Name designation dateOfJoining... (1 Reply)
Discussion started by: shilendrajadon
1 Replies
Login or Register to Ask a Question