LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-23-2011, 02:08 PM   #1
s_linux
Member
 
Registered: Jul 2009
Posts: 83

Rep: Reputation: 15
read file line by line


so I have a script that creates couple of txt files. First file output is something like below..
cn=test,ou=something,ou=some,o=org
cn=testa,ou=something,ou=some,o=org
cn=testb,ou=something,ou=some,o=org

second file output is something like below..
usera
userb
userc

Quote:
userdn=`ldapsearch -x -h $server -LLL "(objectclass=person)" dn | grep dn: | cut -d" " -f2 > userdn.txt

for i in $(cat userdn.txt);do

ldapsearch -h $server -p 389 -x -D $admid -w $admpwd -s one -b "$userdn" dn | grep dn: | cut -d" " -f2 | cut -d"=" -f2 | cut -d"," -f1 > user.txt

for i $(cat user.txt);do

echo "$userdn"
done
done
when I ran both ldapsearch commands invidually, they work fine. But when I ran script, I got first file correctly but not the second one. It looks like its not reading the first file correctly and not setting the variable ($userdn) value correctly in the second ldapseach command.
I want read first file first line and run the second ldapsearch and continues, then read the second line..and so on.
Could some one help me with this..
Thanks
 
Old 03-23-2011, 02:55 PM   #2
s_linux
Member
 
Registered: Jul 2009
Posts: 83

Original Poster
Rep: Reputation: 15
Nevermind. I got it. I'm not suppose to use $userdn variable instead I should use "i" in second ldapsearch command.
Anyways Thanksagain.
 
Old 03-23-2011, 03:26 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
What kind of information are you actually trying to extract from LDAP?
It might be possible to get it w/o the intermediate files.



Cheers,
Tink
 
Old 03-23-2011, 08:22 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I would have said that the first line, as it stands, would have thrown an error as there is no closing backtick and that userdn at the front would never have been set,
assuming line did work, as all the information is redirected to a file.

The other danger I see is that you have a for loop inside a for loop and they both use the same index, namely 'i'. So the results would have been erroneous.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash : read every line from text file starting at given line number quadmore Programming 4 02-20-2009 12:29 PM
help with c program to read each line from text file, split line , process and output gkoumantaris Programming 12 07-01-2008 12:38 PM
php - Read file line by line and change a specific line. anrea Programming 2 01-28-2007 01:43 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration