0

I have very simple command which generating STDOUT which i want to do /dev/null but somehow it's not working or i am missing something here.

$ ldapsearch -Y GSSAPI -b "cn=users,cn=accounts,dc=example,dc=com" "uid=foo" | grep krbPasswordExpiration | tail -n1 | awk '{print $2}'
SASL/GSSAPI authentication started
SASL username: admin@EXAMPLE.COM
SASL SSF: 256
SASL data security layer installed.
20200608022954Z     <---- This is my krbPasswordExpiration value.

But if you see in above command SASL line which is just stdout which i want to do /dev/null so i have tried following but it seems not working.

$ ldapsearch -Y GSSAPI -b "cn=users,cn=accounts,dc=example,dc=com" "uid=foo" | grep krbPasswordExpiration | tail -n1 | awk '{print $2}' 2> /dev/null

what other way i can get rid of it?

2

You need to be aware of what command is doing the output to stderr and make sure the redirection is associated with that command.

You can think of pipes as having ( ) around the commands

So

a | b | c

can be thought of as

( a ) | ( b ) | (c )

(That's not literally how it works, but it's a mental model).

And the redirection happens inside the brackets.

So it's clear that

( a ) | ( b ) | ( c 2>/dev/null )

doesn't redirect the error message from "a"

but

( a 2>/dev/null) | ( b ) | ( c )

does

And so, your command redirected the error from the awk command. You really want to redirect the error from ldapsearch.

So

$ ldapsearch -Y GSSAPI -b "cn=users,cn=accounts,dc=example,dc=com" "uid=foo" 2>/dev/null | grep krbPasswordExpiration | tail -n1 | awk '{print $2}'
  • Damn it, good catch, i didn't realize that i am doing bunch of | thank you for second set of eye :) – Satish Oct 23 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.