The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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 12:19 PM
Variable in While Loop Nested If geass Shell Programming and Scripting 6 03-26-2007 07:09 PM
Nested while read line loop Rakker Shell Programming and Scripting 7 06-24-2005 08:42 AM
nested loop chinog Shell Programming and Scripting 5 04-20-2005 11:45 AM
nested read TioTony Shell Programming and Scripting 2 03-05-2004 03:11 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 12-11-2007
littlefrog littlefrog is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 12
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!
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:33 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0