0

Hi Team,

Problem Description:
Well i have a script with me(attached) which monitors the response time of each file and sends mail according to its severity

As i am very new to this script it involves mix of korn shell plus html.
Request your guidance on the same.

Requirement:
Presently it sends us through mail, irrespective of all. i.e (pass(green),fail(red),not-available(yellow)..

But now on-wards i need to receive mail only when its fail(red).
I dont want the pass(green) and not-available(yellow).

Please see the attached script and request your guidance on the same in-order to achieve the desired result.

Regards
Whizkidash

Attachments
#!/usr/bin/ksh

function gen_html {
today_filename=cbto.efm.$workload.$datefield
filename=$1
echo "<html>
        <body bgcolor=white><table align=center border=1 bgcolor=silver><tr><th colspan=4 align=center> File Transfer status for BACS on :  `date`</th></tr>
        <tr bgcolor=blue><th><font color=white>Filename</font></th><th><font color=white>Expected Time</font></th><th><font color=white>Arrival Time</font> </th><th><font color=white>Diff(Min)</font></th</tr>" > $OUTFILE


        awk '{ if ($2 != "ad" && $2 != "\#N\/A") { print $1" "$NF } }' cbto.filelist.mq3p.tt  | while read name eta
do
#echo $name" expected on "$eta
eval "egrep -q $name $filename"
if [ $? -eq "0" ]
then
        timeA=`grep $name $filename | awk '{print $2}' | awk -F\| '{print $1}'`
        timeE=$eta
        HRe=`echo $timeE | awk -F: '{print $1}'`
         MINe=`echo $timeE | awk -F: '{print $2}'`
        HRe=`expr $HRe \* 60`
        MINe=`expr $HRe + $MINe`
        HRa=`echo $timeA | awk -F: '{print $1}'`
        MINa=`echo $timeA | awk -F: '{print $2}'`
        HRa=`expr $HRa \* 60`
        MINa=`expr $HRa + $MINa`
        DIFF=`expr $MINa - $MINe`
        if [ $DIFF -gt 15 ]
        then
                if [ $DIFF -gt 30 ]
                then
                        COLOR="red"
                else
                        COLOR="#FF8000"
                fi
        else
                        COLOR="amber"
        fi
        echo "<tr><td>$name</td><td> $timeE </td><td> $timeA </td><td bgcolor=$COLOR> $DIFF </td></tr>" >> $OUTFILE
        echo "$name  $timeE  $timeA"
else
        timeE=$eta
        HRe=`echo $timeE | awk -F: '{print $1}'`
        MINe=`echo $timeE | awk -F: '{print $2}'`
        HRe=`expr $HRe \* 60`
        MINe=`expr $HRe + $MINe`
        HRc=`date | awk '{print $4}' | awk -F: '{print $1}'`
        MINc=`date | awk '{print $4}' | awk -F: '{print $2}'`
        HRc=`expr $HRc \* 60`
        MINc=`expr $HRc + $MINc - 10`

        if [ $MINc -gt $MINe ]
        then
        echo "<tr><td>$name </td><td> $eta </td><td bgcolor=yellow>Not Arrived </td></tr>" >> $OUTFILE
        fi
fi
done
echo "</table><br><br><br><br>" >> $OUTFILE

echo "<table align=center border=1 bgcolor=silver><tr><th colspan=4 align=center> Transfer status for Ad-Hoc Files for BACS on : `date`
        </tr><tr><th>Ad hoc files: No action required on non arrival</th></tr><tr bgcolor=blue><th><font color=white>Filename</font></th><th><font color=white>Arrived Time</font></th</tr>" >> $OUTFILE
awk '{ if ($2 == "ad") { print $1} }' cbto.filelist.mq3p.tt  | while read name
do
        eval "egrep -q $name $filename"
if [ $? -eq "0" ]
then
        timeA=`grep $name $filename | awk '{print $2}' | awk -F\| '{print $1}'`
        COLOR="green"
else
        timeA="Not Arrived"
        COLOR="yellow"
fi
        echo "<tr><td>$name </td><td bgcolor=$COLOR> $timeA </td></tr>" >> $OUTFILE
done

echo "</table><pg>" >> $OUTFILE
}

# This script looks up the Connect Direct file logs on a node and then filters them for the filelist mentioned in t he file cbto.filelist. It then prepares the repory in a format that can be directly read by MS-Excel using pipe del imited fields
function interfaces
{
        grep RECI=CTRC | nawk -F\| '
        {
                for(i=1;i<=NF;i++)
                {
                        split($i,fields,"=")
                        record[fields[1]]=fields[2]
                }
#               gsub(/[0-9]/,"*",record["DFIL"])
                gsub(/\*+/,"*",record["DFIL"])
#               gsub(/[0-9]/,"*",record["SFIL"])
                gsub(/\*+/,"*",record["SFIL"])

                if(record["FROM"] == "S")
                {
                        src_node=record["SNOD"]
                        dest_node=record["PNOD"]
                }
                else
                {
                        src_node=record["PNOD"]
                        dest_node=record["SNOD"]
                }

                name=src_node "," record["SFIL"] "," dest_node "," record["DFIL"]
                interfaces[name]=record["STAR"]
                volumes[name]+=record["DBYW"]
                transfers[name]+=1
                averages[name]=int(volumes[name] / transfers[name])
        }
        END{
                for (name in interfaces)
                {
                        print interfaces[name] "," name "," volumes[name] "," transfers[name] "," averages[name]
                }
        }' | nawk -F, '
                BEGIN{
                        names[1]="Last used"
                        names[2]="Sending Node"
                        names[3]="Source File"
                        names[4]="Receiving Node"
                        names[5]="Destintation File"
                        names[6]="Volume"
                        names[7]="Transfers"
                        names[8]="Average Transfer"
                }
                {
                                printf "%s",$1
                        for(i=2;i<=NF;i++)
                        {
                                printf "|%s",$i
                        }
                        printf "\n"
                }
        '
}
# Remember, this is a quick script, so you have to help
# yourself a little bit. For starters, manually define the
# input parameters
workload=mq3p

# Basic housekeeping and cleanup
rm -f cbto.efm.*


#Creating today's file
datefield=`date +%Y%m%d`
#datefield=20090820
today_filename=cbto.efm.$workload.$datefield
echo "Last used|" "Sending Node|" "Source File|" "Receiving Node|" "Destintation File|" "Volume|" "Transfers|" " Average Transfer" > $today_filename
cat /wload/$workload/app/connectd/work/aix.$workload/S$datefield.* | grep -f cbto.filelist.$workload | interfaces >> $today_filename

## Main

OUTFILE=${today_filename}.html
gen_html $today_filename
rm $today_filename
2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by whizkidash
0

When you do this

if [ $DIFF -gt 30 ]
                then
                        COLOR="red"

Add this line

if [ $DIFF -gt 30 ]
                then
                        COLOR="red"
                        needToSendEmail=1

Test that flag when you're about to send email.

0

Hi Saleem,

Many thanks for your mail.

Well sorry i didnt mentioned that there is a seperate script which runs after few minutes once the main script runs

Attached the mailing script.


As per my understanding.. if ?

except if [ $DIFF -gt 30 ]
then
COLOR="red"

I have hashed out the remaining .Also excluding the MS-Excel conversion too.

And the mailing script(attached) then sends the mail

Not sure.. if the above yeilds me with the result.. or is there any other opinion from your end. where on i need to do changes to the main script pointing towards the mailing script

Please advice!

Cheers!
Whizkid

Attachments
. $HOME/.profile
Today=`date +%Y%m%d`
TodaySubject=`date +%d-%m-%Y`
Timing=`date +%c`

Logs=/wload/mq3p/home/mq3pcd/logs/EmailLog.txt

#echo $Today
#echo $TodaySubject


( echo "Subject: External File Monitoring Report-$TodaySubject"; echo "MIME-Version: 1.0"; echo "Content-Type: text/html"; echo "Content-Disposition: inline"; echo "To: tom@xyz.com, sid@xyz.com; echo "Cc:
abc@xyz.com"; cat /wload/mq3p/home/mq3pcd/scripts/MessageHtml1.txt /wload/mq3p/home/mq3pcd/cbto.efm.mq3p.$Today.html /wload/mq3p/home/mq3pcd/scripts/MessageHtml2.txt;) | /usr/sbin/sendmail -t >> $Logs

echo "Report sent successfully on "$Timing >> $Logs
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.