0

I am trying to write a script that ouputs the username,real name, and account expriation date. This is the code I have so far.

awk -F: '$3 > 1000 { print $1, $5 }|grep /etc/shadow (print $9)to_date('1970-01-01','YYYY-MM-DD') + numtodsinterval(1244108886,'SECOND')

input:

smithj:Ep6mckrOLChF.:10063:0:99999:7:::
westf:Ep7uopliokmmm.:1058:0:1087654:7:::
martinezj:GHolimpjk90.:1010:0:1008759:7::

output:

John Smith           Password expires never
Frank West           Password expires: May 8th 2015
Jose Martinez        Password expires: August 12th 2015
Ed Morton
  • 188,023
  • 17
  • 78
  • 185
Scifiguy
  • 1
  • 1
  • I would think you want to pipe grep into awk. Also it's missing a closing ' or nesting ''' ... For example: http://unix.stackexchange.com/questions/169911/writing-a-script-that-outputs-local-users-and-their-password-expiration-date – Kevin Seifert Mar 19 '15 at 14:30
  • Can you explain the problem you are having with it? – NathanOliver Mar 19 '15 at 14:34
  • I just want to make sure the synatx is right because im not really sure how to output 2 files with a pipe. Also, I'm not 100 % sure that printing out &9 with the to date will show the date in normal terms. – Scifiguy Mar 19 '15 at 14:40
  • I want the script to show only the users that actully login. Root expires never user1 expires March 20 2015 – Scifiguy Mar 19 '15 at 15:02
  • Almost there - now you've added sample input and expected output but you haven't told us how to map one to the other. How does `smithj` in the input file become `John Smith` in the output? From what field of `smithj:Ep6mckrOLChF.:10063:0:99999:7:::` are you determining that his password never expires? From which field(s) of `westf:Ep7uopliokmmm.:1058:0:1087654:7:::` are you getting `Frank West` and that his password expires on `May 8th 2015`? I strongly suspect you actually have 2 input files to process and so far you've only shown us one of them so we're missing a lot of pieces of the puzzle. – Ed Morton Mar 19 '15 at 19:41
  • I am linking the user names to the full name in the etc\passwd file. Yes I assume that 9 repeating means the password never expires. I didn't actually do the calculations. – Scifiguy Mar 19 '15 at 19:52

1 Answers1

0

Assuming you have permission to view the shadow file, this will output the username, real name, and account expiration date, colon separated:

join -t: -o 0,1.5,2.8 <(sort /etc/passwd) <(sort /etc/shadow)

That spits out the expiry date as number of days since the epoch. This might be better:

user=someone
IFS=: read username name < <(getent passwd "$user" | cut -d: -f1,5)
expiry=$(chage -l "$user" | awk -F': ' '/^Account expires/ {print $2}')
printf "%s\n" "$username" "$name" "$expiry"
glenn jackman
  • 238,783
  • 38
  • 220
  • 352