The error occurs when the 5th field, maximum password age, of /etc/shadow is empty. Assuming that means there is no point in processing users for which this data does not exist, the script can be fixed by

Code:

c=`echo -e $uname | awk -F: '{print$5}'`
[[ $c = '' ]] && continue

Another problem discovered with the script was that it fails on line 53 for users that are listed in /etc/password but not in /etc/shadow. In this case

EDIT: all three users have been added since OS installation. Two have not had a password set. The other changed its own password using the passwd command; its passwd is in /etc/passwd, encrypted. Not ideal!

EDIT2:
The script could be modified to generate an error message for users not listed in /etc/shadow

and I want to grep two users like test1 and test2, where their output should be like below.

Password for test will expire on Thu Dec 20 00:22:17 2012

chrism01

11-20-2012 01:36 AM

Can you show the current version of your script?
In any case, for embedded vars, you should really use {} thus

Code:

OUTPUT="/var/log/chk_users_expiry.${HOST}.log"

so the parser can tell when the varname starts/stops.

linosaurusroot

11-20-2012 03:35 AM

Quote:

Originally Posted by chrism01
(Post 4833061)

Can you show the current version of your script?
In any case, for embedded vars, you should really use {} thus

Code:

OUTPUT="/var/log/chk_users_expiry.${HOST}.log"

so the parser can tell when the varname starts/stops.

The variable name starts at $ and ends at the first character that's not legal in a variable name - in this case the dot. Supposing the next character after the variable had been [a-zA-Z0-9_] then you'd need the {}.