Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to run a command on a single line that will tell me if the flag is set for a user's password to be changed on next login. This command will interpret the output and return a true/false.

If the PWMC flag is NOT set, I get a date stamp like this:

pdbedit -L -v <USER.NAME> | grep "Password must change:"
> Password must change: Wed, 30 Oct 2013 08:54:01 CDT

If the PWMC flag IS set, the command returns this:

pdbedit -L -v <USER.NAME> | grep "Password must change:"
> Password must change: 0

So how would I compose a command that can be run on a single line that will tell me through a true/false statement that the PWMC flag is set for a given user?

Thanks!

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Taking "return a true/false" to mean echo the string "true" or "false", then this one-liner should do it:

pdbedit -L -v "$USER_NAME" | if grep -Eq 'Password must change:\ +0'; then echo "true"; else echo "false"; fi
share|improve this answer
    
Totally works. Exactly what I was looking for! –  Hamking Aug 15 '13 at 21:29
    
@Hamking: That is funny. This is not what you asked for. This code always returns true and writes true or false string to stdout according to the PWMC flag. Could you please correct your question? ... This command will interpret the output and write a true/false string. @tehsven: The backslash before space in the grep pattern is unnecessary but in common grep implementations it should not be harmful. –  pabouk Aug 19 '13 at 8:47

and as an alias...

alias checkpwd='_(){ pdbedit -L -v $1 | if grep -Eq "Password must change:\ +0"; then echo "true"; else echo "false"; fi }; _'

share|improve this answer
    
What is the reason behind defining the alias? It seems to be redundant and it even redefines the function every time the alias is being called. Just define the function directly: checkpwd() { pdbedit -L -v "$1" | if grep -Eq "Password must change: +0"; then echo true; else echo false; fi } Also please enclose the parameter to be expanded between double quotes. The code then would be functional with usernames containing spaces. –  pabouk Aug 19 '13 at 11:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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