Hello
I read a lot of post related to this topic, but nothing helped me.
I'm running a ksh script with subshell what processing some ldap command. I need to check output for possible errors.
#!/bin/ksh
...
readinput < $QCHAT_INPUT |&
while read -p line
do
echo $line
...
fi
done | ldapadd -x -h $HOST -p $PORT -D cn=$USER -w $PASSWD -c
sttout output:
adding new entry "qchatUserId=21999013000010,ran=cdma,key=qchatUserIdNewTest,o=sprintpcs,o=sprintpcs.com"
ldap_add: Already exists (68)
adding new entry "qchatUserId=000000mig1,ran=cdma,key=qchatUserIdNewTest,o=sprintpcs,o=sprintpcs.com"
ldap_add: Already exists (68)
ldapadd: invalid format \(line 1\) entry: ""
I would like to have the same output in the file.
I tried such redirecting:
done | ( ldapadd -x -h $HOST -p $PORT -D cn=$USER -w $PASSWD -c 2>&3 1>&3 ) 3>log
done | (ldapadd -x -h $HOST -p $PORT -D cn=$USER -w $PASSWD -c 2>&1) | tee log
done | ldapadd -x -h $HOST -p $PORT -D cn=$USER -w $PASSWD -c > log 2>&1
All have the same useless output:
$ cat log
ldap_add: Already exists (68)
ldap_add: Already exists (68)
ldapadd: invalid format (line 1) entry: ""
adding new entry "qchatUserId=21999013000010,ran=cdma,key=qchatUserIdNewTest,o=sprintpcs,o=sprintpcs.com"
adding new entry "qchatUserId=000000mig1,ran=cdma,key=qchatUserIdNewTest,o=sprintpcs,o=sprintpcs.com"
I red that stdout is buffered and stderr not. But none solutions were working.
So is there a way how to force correct order in the file?
out1
err1
out2
err2
out3