#! /bin/bash
`sqlplus -s <username>/<passwd>@dbname` << EOF
set echo on
set pagesize 0
set verify off
set lines 32000
set trimspool on
set feedback off
`SELECT starts_with, SUM (total_records) total_records
FROM (SELECT ID,
(CASE WHEN ID LIKE '2%' THEN '2____'
WHEN ID LIKE '3%' THEN '3____'
WHEN ID LIKE '99%' THEN '99____'
END
) starts_with,
total_records
FROM tr
where ( id like '2%' or id like '3%' or id like '99%'))
WHERE tr.TIMESTAMP > SYSDATE - 75 / 1440
AND tr.TIMESTAMP <= SYSDATE - 15 / 1440
GROUP BY starts_with;
`
exit;
EOF
1.Firstly, how can i schedule the script to run after every 1 hr ?
2.Secondly, the requirement is to send an email on condition such as :
if total_records < 1, then an UP ALERT notification email should be send to [email protected].
And as soon as the total_records gets greater than 1, then again DOWN ALERT notification email is send to [email protected].
NOTE : Till total_records > 1, no such above thing (pt.2) to be followed. Only, when it total_records < 1, we need to follow step 2.
Here, total_records represents transactions, so it will change in every hour (as the tr.TIMESTAMP
signifies). tr represents transaction table.