1

I have am writing a script to list the quota of all the users in my LDAP directory. For this, I use ldapsearch with the appropriate filters to get a list of my usernames in a file. Next I run that file through a while loop which reads the file line-by-line and uses a here document to send the username to the cyrus shell. This is what the loop looks like:

while read userName;do

        cyradm -u cyrus -w my_cyrus_password  localhost << sample
lq user/$userName 
sample

done</home/myuser/tempfiles/tempnames.txt

where lq is the cyradm command to list quota for a user.

I need to output the username and its corresponding quota into a file. How do I do that from within the loop?

rahuL
  • 3,330
  • 11
  • 54
  • 79
  • Is there any type in the 'input the username and its corresponding quota into a file'? Should it be 'output the username and its corresponding quota to a file' instead? – SSaikia_JtheRocker Aug 15 '13 at 10:02
  • @JtheRocker - Sorry, was a typo. Corrected. – rahuL Aug 15 '13 at 10:05
  • Try this -> `echo $(cyradm -u cyrus -w my_cyrus_password localhost << sample lq user/$userName sample) > outfile` – SSaikia_JtheRocker Aug 15 '13 at 10:10
  • I get the following error `./testscript: line 12: warning: here-document at line 12 delimited by end-of-file (wanted 'sample')` – rahuL Aug 15 '13 at 10:15
  • @JtheRocker - Fized it. Moved the `) > outfile` section to a new line. That fixed it. Could you update it as the answer please? – rahuL Aug 15 '13 at 10:19

1 Answers1

1

Hope you tried this ->

while read userName;do

echo $(cyradm -u cyrus -w my_cyrus_password localhost << sample
lq user/$userName 
sample
) >> outfile

done</home/myuser/tempfiles/tempnames.txt
SSaikia_JtheRocker
  • 5,053
  • 1
  • 22
  • 41