Take the follow commands (debian sid bash shell):
n=0;
while [ $n -lt 1000 ];
do
ldapsearch -x -h ldap -b 'dc=company,dc=com' uid |
tee /var/tmp/ldap-search.$n |
grep ^uid |
awk '{print $2}' |
sort |
{ tee a | head -1 ; tail -9 a; rm a; } |
md5sum
((n++));
done | sort | uniq -c
Result:
15 01755713a62aa7e6c22a56e3b1d8f140 -
2 bcdfba835b152d70f78018b1bf9c05b1 -
983 c5b4e951bb8a73809be2a4b69789f831 -
And all ldapsearch output are the same:
md5sum /var/tmp/ldap-search.* | uniq -w32
bded37d641d33fb9b47b58e47c8a1a1a /var/tmp/ldap-search.0
If I delete "{tee a | head -1; tail -9 a ; rm a; } " from the command
then I get the correct output (all the outputs is the same):
1000 b0ffe3bcb3569e81e6e9a0f319e462a5 -
Do you know why could be this issue ?
Thanks in advanced
tee may be killed by a SIGPIPE if "head" terminates before tee
manages to write everything.
You could do:
{ cat > a; head -1 a; tail -9 a; rm a; }
Or use sed '1!d' instead of "head -1" as it doesn't exit until
the whole input has been read.
--
Stéphane