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 :), 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

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

    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

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:

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:

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)

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

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.

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;