1

I am using following code to perform an operation. But everytime "ldap_bind: Invalid credentials (49)" is getting printed on the console. I dont want this to be printed on the console and rather it should be suppressed. How to achieve it? code:

LDAP_CONF="/etc/opt/nokia/ldapserver.conf"
bindError="ldap_bind: Invalid credentials (49)"
basedn=`cat $LDAP_CONF | grep basedn | cut -d " " -f2`
verify=`su - omc -c "ldapsearch -x -n -D 

"uid=$userName,ou=people,ou=accounts,$basedn" -w $newPswd"`

if echo "$verify" | grep -q "$bindError"; then
    printPasswdLog "${ERR}" "bind to ldap server failed"
else
    printPasswdLog "${INF}" "bind to ldap server Successful for $userName "
fi

I am getting the below output:

ldap_bind: Invalid credentials (49) Wed Jun 3 12:45:56 EEST 2015| INFO | bind to ldap server Successful for nwi3system

1
  • basedn=`cat $LDAP_CONF | grep basedn | cut -d " " -f2` is better written as basedn=$(grep based $LDAP_CONFIG) | cut -d" " -f2. See also smallo.ruhr.de/award.html Commented Jun 4, 2015 at 8:02

2 Answers 2

1

If you really want to suppress all error messages, just put this at the start of the script:

exec 2> /dev/null

But you really don't want to do that. It's probably sufficient to do:

verify=$(su - omc -c "ldapsearch -x -n -D 

uid=$userName,ou=people,ou=accounts,$basedn -w $newPswd" 2> /dev/null)

but you don't want to do that either. Why do you want to throw away a perfectly good error message to replace it with one that contains less information?

Sign up to request clarification or add additional context in comments.

Comments

0

You can redirect your error to some other file or to /dev/null. You can use this way

./SCRIPT 2> /dev/null

This will redirect error to /dev/null and no record will be of error.

Instead better will be to record it somewhere. Try this

./SCRIPT 2>> error.txt

This will create a file and all errors will be recorded there.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.