Looping problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looping problem
# 1  
Old 05-09-2016
Looping problem

I need help. I am trying to get this script to send out only one email not multiple emails of the abend. Currently it will send me one then and ther with the first and second one then another email with the first second and third abend and so on. I only want one email sent.





Code:
#!/usr/bin/ksh


LIST=/home/B611568/ABC/daren_scripts/temp/tmpfxxx
ERRORDIR=/home/B611568/ABC/error_directory
EMAILFILE=/home/B611568/ABC/daren_scripts/temp/emailfile

echo "There were errors in the following report file :" > $EMAILFILE
echo >> $EMAILFILE
echo "This files have been moved to $ERRORDIR" >>$EMAILFILE
find /home/B611568/ABC/logs/*.rpt -mtime -5 | egrep -v ftplog >$LIST
while read r1
do
grep CompletionCode $r1 >/dev/null 2>&1
#grep severity $r1 | grep "Completion:" >/dev/null 2>&1
if [ $? = 0 ]; then
grep CompletionCode $r1 | grep "CompletionCode: Value=0" >/dev/null 2>$1
#grep severity $r1 | grep "Completion: Value=0" >/dev/null 2>&1
if [ $? = 1 ]; then
echo $r1 >> $EMAILFILE
echo >>$EMAILFILE
#cat $r1 >>$EMAILFILE
mv $r1 $ERRORDIR
for i in `cat /home/B611568/ABC/daren_scripts/emailparm`
do
cat $EMAILFILE | mail -s $r1 $i@xxxxxxx.cccccccccc.org
done
fi
fi
done<$LIST


Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 05-09-2016 at 02:51 PM.. Reason: drecribee problem/ RudiC: added code tags
# 2  
Old 05-09-2016
Not sure I understand. What is an "abend"? And, if you want just one mail, collect all the messages in one file and send that out once after all list entries have been processed, NOT in a loop in a loop.
# 3  
Old 05-10-2016
An abend is IBM mainframe phrasing for ABnormal END, i.e. an error return. I'm showing my age, I'm sure.

You just need to collect the condition/message/alert and run through once. Are you okay to run all the processing and then this report or are you trying to do it real time, hence the extra loop?



Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with Looping

Hi, guys, What I want is exactly shown below (I modified the former image and it looks like clearer.) https://lh6.googleusercontent.com/-EG8SKkrWEvc/Ube9e-jDiHI/AAAAAAAAAOM/hFNT0UqQPWE/s512/Linux_Study_20130611_001.jpg And with some guys' help, I made it. My script is below: #!/bin/bash #... (20 Replies)
Discussion started by: franksunnn
20 Replies

2. Shell Programming and Scripting

perl: problem in looping! how to get rid

Hi i just want to open 2 files and find difference between cond1 and cond2 and if the difference is greater than or equal to some number say 2 print the lines again in 2 different files. file 1 (1.txt) aqw dfr 34 poilo ggg 98 file 2 (2.txt) qww asd 28 poilo ggg 97 open FILE1,"1.txt" or... (2 Replies)
Discussion started by: anurupa777
2 Replies

3. Shell Programming and Scripting

looping problem

I have been trying to come up with a program that can do this: Say I have a file named "sir" with a single field; 10 229 288 35 83 47 3 I want to create a file "gen" with three fields with the data in file "sire" listed in field 1 while field 2 and 3 are just 1 each like this: SPARSE... (1 Reply)
Discussion started by: iconig
1 Replies

4. Solaris

SVM Solaris 8 Problem. Metastat output looping

Hi friends, I'm newbie to SVM. Just wanna try installed it on one of our server (to do mirroring for disk0 and disk1) but i think im lost until now. :( the steps i've taken is as below:- 1.prtvtoc /dev/rdsk/c1t0d0s2 | fmthard -s - /dev/rdsk/c1t1d0s2 2.metadb -a -c 3 -f c1t0d0s7... (3 Replies)
Discussion started by: kronenose
3 Replies

5. Shell Programming and Scripting

Problem with looping the directories

Hi all, I have a directory which has many sub-directories. Now, I want to check the space of each dir and redirect the output in a file if space exceeds the limit. I have already done it, but the way I did is not very good. I just listed the directories and awked the last column to get the... (5 Replies)
Discussion started by: naw_deepak
5 Replies

6. Shell Programming and Scripting

help with looping

vesselNames values: xxx yyy zzz vesselPlanned values: xxx zzz zzz zzz OIFS="" OIFS=$IFS IFS="\n" (2 Replies)
Discussion started by: finalight
2 Replies

7. Shell Programming and Scripting

for looping

I run into a issue when I try to do sorting of the following with ascending order, one round of for looping seems not working, anyone knows how to use shell or perl? $array = (5,0,3,2,7,9,8) (2 Replies)
Discussion started by: ccp
2 Replies

8. Shell Programming and Scripting

Problem with looping construct

Hi all I have tried to search for this, but keep getting a MySQL db connect error, so am posing the question here, and taking a risk of incurring the wrath of the mods with my first post... I have the following test script: #!/bin/bash HTTPD=`/bin/ps -axcu | /usr/bin/grep httpd... (6 Replies)
Discussion started by: mikie
6 Replies

9. Shell Programming and Scripting

Awk: looping problem!

I am having a problem with awk when I run it with a loop. It works perfectly when I echo a single line from the commandline. For example: echo 'MFG009 9153852832' | awk '$2 ~ /^0-9]$/{print $2}' The Awk command above will print field 2 if field 2 matches 10 digits, but when I run the loop... (5 Replies)
Discussion started by: cstovall
5 Replies

10. UNIX for Dummies Questions & Answers

Help with looping

Hi, Actually I have a file which consists data . for eg names. Then I want my sql query to read this file and produce the output. Currently I am using this FOR EG : FILENAME is NAMES for i in `cat NAMES` { sqlplus -s $CONNECTID << EOF spool rooh set heading off select... (1 Reply)
Discussion started by: rooh
1 Replies
Login or Register to Ask a Question