简体   繁体   中英

Not able to suppress the output in shell script

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM