![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Nested loop not running using cronjob | bihani4u | Shell Programming and Scripting | 9 | 09-26-2007 11:19 AM |
| Variable in While Loop Nested If | geass | Shell Programming and Scripting | 6 | 03-26-2007 06:09 PM |
| Nested while read line loop | Rakker | Shell Programming and Scripting | 7 | 06-24-2005 07:42 AM |
| nested loop | chinog | Shell Programming and Scripting | 5 | 04-20-2005 10:45 AM |
| nested read | TioTony | Shell Programming and Scripting | 2 | 03-05-2004 03:11 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
while read loop w/ a nested if statement - doesn't treat each entry individually
Hi -
Trying to take a list of ldap suffixes in a file, run an ldapsearch command on them, then run a grep command to see if it's a match, if not, then flag that and send an email alert. The list file (ldaplist) would look like - *********** o=company a o=company b *********** ** Note there are spaces in that file that need to be preserved. I was trying to use a for loop and someone suggested a while read loop in order to prevent the space from being treated as a line break. The problem w/ the script i created below is that it runs and only sends one email w/ the info from both entries in ldaplist. It's like my nested 'if' loop is not the right loop to use. I made it so that both entries should have 0 return codes and no luck. Runs once and that's it. Any suggestions to a better structure to this? I would try to use a for i in cat /ldaplist - do .... - but that fails because it doesn't treat the space in the ldaplist (ie: o=company a) as a space - even with " ". while read i do ldapsearch -h server1 -b "$i" objectclass=* ibm-replicationState |grep ibm-replicationState=ready > /dev/null 2>&1 if [ $? -ne 0 ]; then mailx -s "LDAP sync alert on `hostname`" u@mail.com 2>&1 fi done <ldaplist Thanks! |
|
|||||
|
Quote:
Are you saying that your current script (if statement within the while loop) is sending only one email even if there's a bunch of failing ldap suffix lookups? What behaviour do you actually want (ie how many emails and what info in each message): - When there's no suffixes that fail to look up? - When just one fails? - When more than one fails? |
|
||||
|
sorry - just having a difficult time explaining this mess....
What i would like is: For each suffix in the ldaplist file - To run an ldap search command And then grep for 'ibm-replicationState=ready ' If there is a match - do nothing, if not, then send an email. What I'm getting is only one email, and in the body of the email are the other suffixes in my ldaplist file. For instance here is what the body of the email would look like ----- o=group b o=group c ----- So it looks like it runs - but gets triggered on just one of the list items. In this case - o=company a. When i switch the script to do an echo 'echo $i' rather than the mailx statement i get -------- ibm-replicationState=ready o=company a ibm-replicationState=ready o=company b --------- I can skip all of the loops - just thought it would be cool to figur it out. |
|
||||
|
One other note -
I took out the '> /dev/null 2>&1' from the ldap search command - and i only see one instance of 'ibm-replcationState=ready' returned to my screen. - So it looks like for some reason, it's only run that part of the loop once?? - Stange |
|
|||||
|
You can't just do "mailx". mailx wants to read an email. so you need to do something like:
echo fumble | mailx As it is now, mailx is reading from stdin and thus sucking up the rest of the file from your < ldaplist. |
| Sponsored Links | ||
|
|