Objective: Check in /etc/shadow
if user password is locked, i.e. if the first character in the 2nd field in /etc/shadow, which contains the user's hashed password, is an exclamation mark ('!')
Desired output: a variable named $disabled
containing either 'True' or 'False'
Username is in the $uname
varable and I do something like this:
disabled=`cat /etc/shadow |grep $uname |awk -F\: '{print$2}'`
# I now have the password and need one more pipe into the check for the character
# which is where I'm stuck. I would like to do like (in PHP syntax):
| VARIABLE=="!"?"True":"False"`
This is a fragment of a script that will be run by Cron with root permissions, so there is access to all desirable information.
!
, to the shadow password mechanism in Linux operating systems.cat
;grep
can take a file as a command line argument.grep
too;awk
is perfectly capable of finding a string in a file.!
. So, you're technically right, but that seems like a typo in the question rather than a flaw in the underlying intent.