I have to audit the users accounts on our linux servers in each environment so I want to script checking whether each account is expired or not. I have a for loop that's pulling user accounts listed in /etc/passwd and stores them in an array.
#!/bin/bash
users = $(awk -F: '{ print $1}' /etc/passwd)
uservar=($users)
for value in "${uservar[0]}"
do chage -l $value
done
Ideally the script would display a username first then on a new line it would show the account expiration date and other info for that user account. The process would repeat for each account. At the moment its just displaying the account expiration and dates for all user accounts without the username so I can't tell the accounts apart. Everything is also stacked on top of each other so its difficult to read. Ideally the output would look like this:
userA
Last Password Change: 1/2/34
Password Expires: 1/2/34
Password Inactive: 1/2/34
.....
userB
Last Password Change: 1/2/34
Password Expires: 1/2/34
Password Inactive: 1/2/34
.....
I would appreciate any help/suggestions on this.