stdout, stderr, and what else? (going insane parsing slapadd output)

Posted by user64204 on Server Fault See other posts from Server Fault or by user64204
Published on 2011-11-30T09:58:05Z Indexed on 2011/11/30 10:01 UTC
Read the original article Hit count: 282

Filed under:
|
|
|
|

I am using slapadd to restore a backup. That backup contains 45k entries which takes a while to restore so I need to get some progress update from slapadd. Luckily for me there is the -v switch which gives an output similar to this one:

added: "[email protected],ou=People,dc=example,dc=org" (00003d53)
added: "[email protected],ou=People,dc=example,dc=org" (00003d54)
added: "[email protected],ou=People,dc=example,dc=org" (00003d55)
.########              44.22% eta 05m05s elapsed             04m spd  29.2 k/s 
added: "[email protected],ou=People,dc=example,dc=org" (00003d56)
added: "[email protected],ou=People,dc=example,dc=org" (00003d57)
added: "[email protected],ou=People,dc=example,dc=org" (00003d58)
added: "[email protected],ou=People,dc=example,dc=org" (00003d59)

Every N entries added, slapadd writes a progress update output line (.######## 44.22% eta 05m05s elapsed ...) which I want to keep and an output line for every entry created which I want to hide because it exposes people's email address but still want to count them to know how many users were imported

The way I thought about hiding emails and showing the progress update is this:

$ slapadd -v ... 2>&1 | tee log.txt | grep '########'
# => would give me real-time progress update
$ grep "added" log.txt | wc -l
# => once backup has been restored I would know how many users were added

I tried different variations of the above, and whatever I try I can't grep the progress update output line.

I traced slapadd as follows:

sudo strace slapadd -v ...

And here is what I get:

write(2, "added: \"[email protected]"..., 78added: "[email protected],ou=People,dc=example,dc=org" (00000009)
) = 78
gettimeofday({1322645227, 253338}, NULL) = 0
_########    44.22% eta 05m05s elapsed      04m spd  29.2 k/s    ) = 80
write(2, "\n", 1
)      

As you can see, the percentage line isn't sent to either stdout or stderr (FYI I have validated with known working and failing commands that 2 is stderr and 1 is stdout)

Q1: Where is the progress update output line going?
Q2: How can I grep on it while sending stderr to a file?

Additional info: I'm running Openldap 2.4.21 on ubuntu server 10.04

© Server Fault or respective owner

Related posts about ubuntu

Related posts about ldap