Sponsored Content
Full Discussion: UNIX scripting
Top Forums Shell Programming and Scripting UNIX scripting Post 302973513 by bcarosi on Wednesday 18th of May 2016 10:02:41 AM
Old 05-18-2016
Code:
echo "There were errors in the following report file for Xeenos:" > $EMAILFILE
echo >> $EMAILFILE
echo "This files have been moved to $ERRORDIR" >>$EMAILFILE
 find /home/xxxxxx/ABC/logs/*.rpt -mtime -9 | 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
           if [ $? = 1 ]; then
           echo $r1 >> $EMAILFILE
           echo >>$EMAILFILE
           mv $r1 $ERRORDIR
                for i in `cat /home/xxxxxx/ABC/xeenos_scrpts/emailparm`
                do
                 cat $EMAILFILE | mail -s $r1 $i@der.aes.com
                done
          fi
   fi
done<$LIST

******************
this script works perfect but it keeps adding to the email each file..For instance if 4 files have a rc 4 then an email will go out with the first one then another email will go out with the first and seconf one, then another email will go out with first second and third one listed in the email. I just want one email for each file that has a rc 4.

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

NOT LIKE:

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



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


---------- Post updated at 09:47 AM ---------- Previous update was at 09:27 AM ----------

Quote:
Originally Posted by Don Cragun
I agree with pravin27 that there is no way to know what is wrong with this script if you don't clearly describe what it is supposed to do... But, there are some obvious problems:
Since you don't indent your code, it is somewhere between difficult and impossible to see the structure of your code.
  1. You create $MAILFILE before you start your loops (saying that errors have been detected (before you know if any errors have been detected) and add notes to that file during the outer loop. But the contents of that file are not cleared when you move on to a new file in the loop and the contents of that file (which one might assume from the name is to be e-mailed to someone is never used by this script to do anything but add lines to it) are never sent to anyone.
  2. Using cat to print the contents of a directory is generally a waste of time; a directory is not a text file. And, whether you use cat or the much more efficient file redirection to get the contents of a directory, input to the mail command needs to be text; not the contents of a directory.
  3. Do you really need to send individual e-mails to all of the recipients listed in emailparm? Why not create a list of recipients outside the loop and just send one e-mail?
I am sorry but I am just starting Unix scripting. So with the cript you just sent me don't I need to define the variable RECIPIENTS with every ones name in it so that it will mail to recipients. and when I do that do I actually place their full email address with a comma or a colon?

---------- Post updated at 10:02 AM ---------- Previous update was at 09:47 AM ----------

Code:
#!/usr/bin/ksh
#RECIPIENTS=bcarosi
ERRORDIR=/home/p611568/d2e/error_directory
 while read -r i
 do  RECIPIENTS="$RECIPIENTS $i@stryder.aessuccess.org"
 done < /home/p611568/d2e/xeenos_scripts/emailparm
 find /home/p611568/d2e/logs/*.rpt -mtime -10 ! -name '*ftplog*' | while read -r r1
# find /home/p611568/d2e/logs/*.rpt -mtime -8 ! -name '*ftplog*' | while read -r r1
 do  if grep -q CompletionCode "$r1"
     then
         if ! grep CompletionCode "$r1" | grep -q "CompletionCode: Value=0"
         then
             ( echo " There were errors in the following report file for Xenos:"
               echo
               echo "This files have been moved to $ERRORDIR"
               echo "$r1"
             ) | mail -s "$r1" $RECIPIENTS
             mv "$r1" "$ERRORDIR"
         fi
     fi
 done
$

******************
while doing this it just runs in a loop it does not end??????

Last edited by RudiC; 05-18-2016 at 11:09 AM.. Reason: Added code tags (again).
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
All times are GMT -4. The time now is 10:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy