I have the following output:
dante
Last password change : Aug 18, 2017
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
Linux shell : /bin/bash
marion
Last password change : Aug 28, 2017
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
Linux shell : /bin/bash
This output is done with the following command:
cat /etc/passwd | xargs -n1 -I{} bash -c 'a=`echo "{}" | cut -f1 -d:`; echo -e "\n$a"; chage -l $a; echo -e "Linux shell\t: " `echo "{}" | cut -f7 -d:`' >> users-list.log
I would need for each username to get and add the groups that is belonging to in the user-list.log. For example:
dante
Last password change : Aug 18, 2017
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
Linux shell : /bin/bash
Groups : dante, prime, trm
marion
Last password change : Aug 28, 2017
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
Linux shell : /bin/bash
Groups : marion, secondary, krq
I need to run everything in one command and all quotes should be escaped because I will run it in Ansible. If is any other way to make it run in Ansible, I am opened to any suggestions.
Best regards, Romain