I created an account "
diag" and set it as expired (
usermod --expiredate 1). Then I have a script which I want to run to log into it, so in the script I use the following command:
su -s /bin/bash - diag
This outputs like so:
Your account has expired; please contact your system administrator su: Authentication failure (Ignored) diag@computer:~$
And then I'm able to use the account, as expected.
I want to suppress the first three lines, the warning about the expired account. I tried adding
2> /dev/null to the end of the command, but that suppresses all the output from bash; I just get a blank response, and I can type commands into it and see the result from them, but I see no bash prompt. I tried adding just
> /dev/null and that does nothing.
So I've deduced that apparently
su is piping all its output over
stderr. How can I get
su to just suppress those first three lines, but otherwise act normally as if the account weren't expired?