Need to implement new CRON job or modify the existing one in MDM PROD in coming days, which will sen


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to implement new CRON job or modify the existing one in MDM PROD in coming days, which will sen
# 1  
Old 01-16-2014
Blade Need to implement new CRON job or modify the existing one in MDM PROD in coming days, which will sen

Need to implement new CRON job or modify the existing one in MDM PROD in coming days, which will send email of SQL statement running from past 1 minute.Currently there is one CRON job in PROD, which send below email.

there is one cron job which send email, when there is long running process....but its does not send sql information....



Required details.


1) Long_Running_Processes.ksh<DB2 Instance Name>
<Database Name>MDM
Websphere ESB's
NetQuotesVaries
Every 5/10minsIf a transaction has been executing against the specified database for longer than 60 seconds then an email is sent to the ASWTDBA mailbox.



2) CRON Job details…

ukncsaviv724:uklasdb2:/home/apps/admin/utils/uklasdb2/bin $ cat Long_Running_Processes.ksh
Code:
#!/bin/ksh
 
thisFile="$(whence ${0})"
thisDir="${thisFile%/*}"
 
# Environment Setup
. ${thisDir}/../lib/env.ksh
 
# Include Common Functions
. ${thisDir}/../lib/func.ksh
 
# Initialise Logging
LOGFILE=`LogFileName ${1}.${2}`
exec 2>&1
exec 1> ${LOGFILE}
 
# Output a HEADER section to the logfile
LogHeader
 
 
# Two parameters expected. INSTANCENAME, DATABASENAME
if [ $# -ne 2 ]
then
        echo "Usage: `basename $0` <Instance Name> <DB Name>"
        LogFooter
        exit 1
fi
 
# Set some variables for the parameters passed to this script
INSTANCE=${1}
DBNAME=${2}
 
# Check if this DB2 instance is running on this server
RUNNING=`CheckRunningInstance ${INSTANCE}`
if [ ${RUNNING} -eq 1 ]
then
        echo "Instance: ${INSTANCE} is not running on this server"
        LogFooter
        exit 1
fi
 
# Set Env for DB2 instance
SetDB2Env ${INSTANCE}
 
# Connect to DB2 database
ConnectDB2 ${DBNAME}
 
# Run SQL to check if any processes have been running for longer than the specified number of seconds
db2 -x "SELECT  SNAPSHOT_TIMESTAMP, AGENT_ID, APPL_STATUS, CLIENT_PID, APPL_NAME, APPL_ID, AUTH_ID, \
                CLIENT_NNAME, EXECUTION_ID, \
                TIMESTAMPDIFF(2,char(current timestamp - STATUS_CHANGE_TIME)) WAIT_TIME_SECONDS \
        FROM TABLE( SNAPSHOT_APPL_INFO( '${DBNAME}', -1 )) as SNAPSHOT_APPL_INFO \
        WHERE APPL_STATUS = 3 \
        AND   TIMESTAMPDIFF(2,char(current timestamp - STATUS_CHANGE_TIME)) > 60" > ${TEMPDIR}/$$.tmp1
 
if [ $? -ne 0 -a $? -ne 1 ]
then
        echo "Error selecting long running process information"
        LogFooter
        exit 1
fi
 
# Flag file to check if an email has already been sent
EMAILCHECKFILE=${ETCDIR}/Email_LongRunningProcess.${INSTANCE}.${DBNAME}.chk
 
# Any long running processes?
LONG=`wc -l ${TEMPDIR}/$$.tmp1 | awk '{print $1;}'`
echo "LONGRUNNINGCOUNT = ${LONG}"
if [ ${LONG} -gt 0 ]
then
        echo "Long Running processes found. Starting monitoring."
        cp ${TEMPDIR}/$$.tmp1 ${DATADIR}/snapshotapplinfoLR.${INSTANCE}.${DBNAME}.${DATESTAMP}.${TIMESTAMP}.txt
 
        # Get a snapshot of the database locks
        SNAPSHOTFORLOCKSFILE=${DATADIR}/snapshotforlocksLR.${INSTANCE}.${DBNAME}.${DATESTAMP}.${TIMESTAMP}.txt
        db2 -x "get snapshot for locks on ${DBNAME}" > ${SNAPSHOTFORLOCKSFILE}
 
        # Check if email has been sent already the last time this ran
        if [ ! -f ${EMAILCHECKFILE} ]
        then
                # Write info to a file containing the body of the email to be sent
                echo "\
${DATESTAMP} ${TIMESTAMP} - Long Running processes found. \
Check the data files in ${DATADIR} on `hostname` for details." > ${TEMPDIR}/$$.tmp2
                echo "\
The processes below have been running for LONGER than 60 seconds." >> ${TEMPDIR}/$$.tmp2
                echo "" >> ${TEMPDIR}/$$.tmp2
                cat ${TEMPDIR}/$$.tmp1 >> ${TEMPDIR}/$$.tmp2
                echo "" >> ${TEMPDIR}/$$.tmp2
                cat ${SNAPSHOTFORLOCKSFILE} >> ${TEMPDIR}/$$.tmp2
 
                # Send an email
                cat ${TEMPDIR}/$$.tmp2 | mailx -s "${INSTANCE} ${DBNAME} has long running processes." ${EMAILALERTS}
                touch ${EMAILCHECKFILE}
        fi
 
        # Run script to collect all relevant diagnostic information
        ${BINDIR}/Data_Collection.ksh ${INSTANCE} ${DBNAME}
else
        # Remove the file that is used to check that en email has been sent
        rm -f ${EMAILCHECKFILE}
fi
 
 
# Tidy up temp files
rm -f ${TEMPDIR}/$$.*
 
# Output Footer section to logfile
LogFooter
 
ukncsaviv724:uklasdb2:/home/apps/admin/utils/uklasdb2/bin $
 
 
ukncsaviv724:uklasdb2:/home/apps/admin/utils/uklasdb2/bin $ cat Data_Collection.ksh
#!/bin/ksh
 
thisFile="$(whence ${0})"
thisDir="${thisFile%/*}"
 
# Environment Setup
. ${thisDir}/../lib/env.ksh
 
# Include Common Functions
. ${thisDir}/../lib/func.ksh
 
# Initialise Logging
LOGFILE=`LogFileName ${1}.${2}`
exec 2>&1
exec 1> ${LOGFILE}
 
# Output a HEADER section to the logfile
LogHeader
 
 
# Two parameters expected. INSTANCENAME, DATABASENAME
if [ $# -ne 2 ]
then
        echo "Usage: `basename $0` <Instance Name> <DB Name>"
        LogFooter
        exit 1
fi
 
# Set some variables for the parameters passed to this script
INSTANCE=${1}
DBNAME=${2}
 
# Check if the DB2 instance is running on this server
RUNNING=`CheckRunningInstance ${INSTANCE}`
if [ ${RUNNING} -eq 1 ]
then
        echo "Instance: ${INSTANCE} is not running on this server"
        LogFooter
        exit 1
fi
 
# Set Env for DB2 instance
SetDB2Env ${INSTANCE}
 
# Connect to DB2 database
ConnectDB2 ${DBNAME}
 
# Loop through each of the snapshot SQL files
for sqlfile in ${ETCDIR}/snapshot*.sql
do
        # Generate an output filename (Remove the .sql from the file)
        STRIPPEDsqlfile=`basename ${sqlfile}`
        OUTFILE=${DATADIR}/${STRIPPEDsqlfile}.${INSTANCE}.${DBNAME}.${DATESTAMP}.csv
        # A couple of temp files and sql files to hold the query and also the data as it is collected
        TEMPFILE1=${TEMPDIR}/$$.tmp1
        TEMPFILE2=${TEMPDIR}/$$.tmp2
        SQLFILE1=${TEMPDIR}/$$.sql1
        SQLFILE2=${TEMPDIR}/$$.sql2
 
        echo "EXPORT TO ${TEMPFILE1} OF DEL" > ${SQLFILE1}
        cat ${SQLFILE1} ${sqlfile} | sed "s/<<DBNAME>>/${DBNAME}/g" > ${SQLFILE2}
        db2 -t -f ${SQLFILE2}
 
        if [ -f ${OUTFILE} ]
        then
                cat ${OUTFILE} ${TEMPFILE1} > ${TEMPFILE2}
                mv -f ${TEMPFILE2} ${OUTFILE}
        else
                mv -f ${TEMPFILE1} ${OUTFILE}
        fi
done
 
# Tidy up any temp files
rm -f ${TEMPDIR}/$$.*
 
# Output Footer section to logfile
LogFooter

ukncsaviv724:uklasdb2:/home/apps/admin/utils/uklasdb2/bin $ Reply Forward

Moderator's Comments:
Mod Comment Please use code tags next time - for your code and data...

Last edited by vbe; 01-16-2014 at 01:51 PM.. Reason: ugly typo...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job - Need to run Cron every quarter at particular time

Hi, 1) If some job supposed to run on 1st of every month at 7 AM In cron job when we have a blackout on the 1st ( i.e when 1st falls on a sunday ) how can we make the job run the next business day? 2) How can we run a job on 25th of every quarter 7 AM(jan,apr,jul,oct) And if 25th... (5 Replies)
Discussion started by: System Admin 77
5 Replies

2. Shell Programming and Scripting

Modify existing values in a file

Hi, I am trying to write a shell script which will modify existing values and take backup of old values. file trying to modify is : /etc/sysctl.conf script name: modify.sh execute ./modify.sh enter ref no: 123 add below values in file sysctl.cnf kernel.shmall = 4194304 ... (7 Replies)
Discussion started by: darling
7 Replies

3. Shell Programming and Scripting

Commented cron job -- cron monitoring

Hi I have a requirement to write a shell script,that will check the all commented job in cron job.Please help !! (2 Replies)
Discussion started by: netdbaind
2 Replies

4. Shell Programming and Scripting

CRON Job to copy database and replace existing database

I have a reseller account with hostgator, which means i have WHM and Cpanel. I have set up a staging environment for one of my wordpress installations (client website), which is essentially sitting at staging.domain.com (live site is at domain.com). The staging website is a complete copy of the... (1 Reply)
Discussion started by: nzrobert
1 Replies

5. Shell Programming and Scripting

how to modify existing env var

greetings, i have the following env variable: LSB_HOSTS='t70cra102 t70cra102 t70cra108 t70cra108'the variable could be any number of host names and sometimes the same name several times. i was hoping there's a way to turn it into the following: NEW_LSB_HOSTS=,,,]always appreciate the help... (2 Replies)
Discussion started by: crimso
2 Replies

6. Shell Programming and Scripting

Cron job running for some days and is not running for some days

Hi.. i have written a shell script and made this script to run on every day night 11: 55 pm using a cron job. This cron job running for some days and is not running for some day. but i need this script to run every day night. Please help me. Here is the cron tab entries, 55 23 * * *... (1 Reply)
Discussion started by: vidhyaS
1 Replies

7. Shell Programming and Scripting

modify Existing MS excel workbook in perl

Hi I need to modify an excel file in perl and for which I installed perl in Linux 1. Open a existing excel file 2. delete an unwanted Sheet called "summary" 3. and i want to insert some data into range of cells ( B1:B11) 4. Remove unwanted value called "Sum" repeated in the... (1 Reply)
Discussion started by: luke_devon
1 Replies

8. Solaris

cron job starts new cron proccess

I run cron in solaris 10 zone. One cron job which syncing files to nfs mounted on container, creates after finishing another cron proccess(/usr/sbin/cron), and after 100 existing cron proccesses next cron job will not start. It's too weird for me, I'm not able to solve this problem. Theoretically... (3 Replies)
Discussion started by: ron76
3 Replies

9. UNIX for Advanced & Expert Users

How to modify an existing pdf with unix shell commands

Hi, I know that to create a pdf file I can use the txt2pdf command. But if I would change an existing pdf file, by inserting lines in particular positions of this file, what can I use? And How? (3 Replies)
Discussion started by: fandwick
3 Replies

10. Shell Programming and Scripting

How to implement cron job to run my reports dynamically?

How to implement cron job. Ex: I need to run SQR reports dynamically by using cron job. How can I implement cron job in shell.. If any one is having sample script in any shell that would be great help to me. Thanks Siva (1 Reply)
Discussion started by: siva
1 Replies
Login or Register to Ask a Question