UNIX scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX scripting
# 8  
Old 05-18-2016
MODIFY THIS script to send one email for each 4 files

this script is currently sending 4 emails:
reading:
Code:
There were errors in the following report file for Xenos:

This files have been moved to /home/p611568/d2e/error_directory
/home/p611568/d2e/logs/Test_Value_4.rpt

/home/p611568/d2e/logs/bf98009_11_1462885241803.rpt

/home/p611568/d2e/logs/bf98009_12_1462885242812.rpt

/home/p611568/d2e/logs/bf98009_13_1462885243819.rpt

I want the script to send one email for each file without a rc0 like this:

Code:
There were errors in the following report file for Xenos:

This files have been moved to /home/p611568/d2e/error_directory
/home/p611568/d2e/logs/Test_Value_4.rpt

currently it send me another one that will say:

Code:
There were errors in the following report file for Xenos:

This files have been moved to /home/p611568/d2e/error_directory
/home/p611568/d2e/logs/Test_Value_4.rpt

/home/p611568/d2e/logs/bf98009_11_1462885241803.rpt

then it will send another email with 3 files ....until it reaches the fourth file. I Nedd to have one email send for each file

If you could just tell me what I am doing wront to correct it I would appreciate it


Code:
#!/usr/bin/ksh

LIST=/home/p611568/d2e/xenos_scripts/temp/tempfile
ERRORDIR=/home/p611568/d2e/error_directory
EMAILFILE=/home/p611568/d2e/xenos_scripts/temp/emailfile

echo "There were errors in the following report file for Xenos:" > $EMAILFILE
echo >> $EMAILFILE

echo "This files have been moved to $ERRORDIR" >>$EMAILFILE

find /home/p611568/d2e/logs/*.rpt -mtime -10 | egrep -v ftplog >$LIST
(while read r1)
       (do
       grep CompletionCode $r1 >/dev/null 2>&1)CODE]
       (if [ $? = 0 ]; then
        grep CompletionCode $r1 | grep "CompletionCode: Value=0"            
          >/dev/null 2>$1
                (if [ $? = 1 ]; then
                 echo $r1 >> $EMAILFILE
                  echo >>$EMAILFILE
                  mv $r1 $ERRORDIR
                      (for i in                                                   
                         `cat /home/p611568/d2e/xenos_scripts/emailparm`
                        do
                        cat $EMAILFILE | mail -s $r1 $i@sxxxxxr.access.org
          done)
     fi)
fi)
done<$LIST

Moderator's Comments:
Mod Comment PLEASE! -- take the following comments on posting to heart, be it first, second, or third paragraph.


Moderator's Comments:
Mod Comment To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)



Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

Last edited by RudiC; 05-18-2016 at 06:29 PM.. Reason: Added / corrected code tags (AGAIN!).
# 9  
Old 05-18-2016
Let me guess: if there were six or ten files in your directory, you'd receive six or ten emails with up to six or ten files.

I think you've been given the reasons for your script's "misbehaviour" that you complain about in Don Cragun's post#3, and even a solution in post#5. Did you read and understand his proposals?

On top of not applying them to your script, you've introduced several new errors in your last version in post#8, e.g. the many pointless opening and closing parentheses or the pointless redirection to /dev/null.

And, last but not least: Please abstain from opening a new thread for the same topic in order not to scatter the discussion all over the place!
# 10  
Old 05-18-2016
In addition to post #3 that RudiC mentioned, also note the last paragraph of post #7 where I explained exactly why the code I suggested does exactly what you have requested and why your code is doing what it is doing.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix Shell Scripting( Calling from Unix to PLSQL)

Hello Experts, I have the following questions to be discussed here at this esteemed discussion forum. I have two Excel sheets which contain Unix Commands llike creating directory the structure/ftp/Copy/Zip etc to basically create an environment. I need help in understanding some of... (1 Reply)
Discussion started by: faizsaadq
1 Replies

2. UNIX for Advanced & Expert Users

Unix scripting

i need help with this problem this is the problem: Write a script that logs how many users login on/off the system over a 5 minute period. It can run in the foreground, and run 4 times a minute. Set a trap that will not allow a CNTRL-C command, and if a CNTRL-C is excuted store the time and date... (1 Reply)
Discussion started by: sportsmansixty6
1 Replies

3. Shell Programming and Scripting

Unix scripting

how to check if a unix script gets executed without errors across all unix platforms. incase if a script gets executed without errors only one platform say AIX, what needs to be done to that script such that it will run all unix platforms like linux, hp, sun etc (2 Replies)
Discussion started by: rmann
2 Replies

4. Shell Programming and Scripting

Unix Scripting

Hi Gurus, I am a system admin in solaris field and ive planned to study unix scripting.ive planned to start reading Mastering Unix scripting by randal.Scripts in that are based on Korn shell(ksh).my question is whether the same scripts can be applied to other shells like bash etc..And... (4 Replies)
Discussion started by: madanmeer
4 Replies

5. UNIX for Dummies Questions & Answers

Unix Scripting

Hi Gurus, I am a system admin in solaris field and ive planned to study unix scripting.ive planned to start reading Mastering Unix scripting by randal.Scripts in that are based on Korn shell(ksh).my question is whether the same scripts can be applied to other shells like bash etc..And... (1 Reply)
Discussion started by: madanmeer
1 Replies

6. UNIX for Dummies Questions & Answers

Help me Out in unix scripting

Hello every one, plz help me out. I m using 4 files in unix, like file1, file2, file3,file4 in which primary key is ID in column(field) of 4 files. On the bases of ID, i want the corresponding field of 4 files in final file let say collected file. In collected file, ID column should occur only one... (16 Replies)
Discussion started by: kaprus
16 Replies

7. UNIX for Dummies Questions & Answers

Unix scripting pl help

Hi All, I am new to Unix Scripting. I have below scenario. I need to write a Unix function with the following. 1. I have table. From this table I need to write a query. SELECT Col1(File_nm),Col2(From_Loc),Col3(To_Loc) FROM A WHERE CONDITION For... (1 Reply)
Discussion started by: sree11
1 Replies

8. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

9. UNIX for Dummies Questions & Answers

Help With Unix Scripting.

Can anybody tell me the best way to learn unix scripting.can you recommend a good book.Please help! (1 Reply)
Discussion started by: hella
1 Replies

10. UNIX for Dummies Questions & Answers

UNIX Scripting

:confused: I need to find a place or places on the Internet where I can find UNIX scripts to view and to modify to make life easy on the UNIX environment. Can someone help me on this. Thanks (7 Replies)
Discussion started by: wolf
7 Replies
Login or Register to Ask a Question