0

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!

2 Answers 2

0

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
2
  • Totally works. Exactly what I was looking for!
    – Hamking
    Aug 15, 2013 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. Aug 19, 2013 at 8:47
0

and as an alias...

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

1
  • 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. Aug 19, 2013 at 11:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .