Find the answer to your Linux question:
Results 1 to 3 of 3
As system administrator I have just implemented expiry dates for my users accounts - this works well. What I would like to know; is there a script or something that ...
  1. #1
    Just Joined!
    Join Date
    Mar 2010
    Posts
    2

    request: script to list account expiry date

    As system administrator I have just implemented expiry dates for my users accounts - this works well.

    What I would like to know; is there a script or something that will provide the current account expire date from the shadow file given a username or better yet from the entire shadow file (with all accounts).

  2. #2
    Just Joined!
    Join Date
    Jul 2011
    Location
    San Diego, CA
    Posts
    7
    chage -l USERNAME does a nice job of displaying password & account aging information from /etc/shadow. I just typed this out on the command line, but you could certainly turn it into a script:

    for LINE in $(grep -v -e nologin -e halt -e shutdown -e sync /etc/passwd | cut -d: -f1,3); do THE_NAME=$(echo $LINE |cut -d: -f1); THE_UID=$(echo $LINE | cut -d: -f2); [ $THE_UID -ge 500 ] && ( echo -n "${THE_NAME}: "; echo $(chage -l $THE_NAME | grep "Account expires" | cut -d: -f2) ); done

    Note that I excluded users with the shells: /sbin/nologin, /sbin/halt, /sbin/shutdown, and /bin/sync. I also filtered the remaining matches to only run chage for users with uid's greater than or equal to 500. Finally, I only extracted the line that relates to a user's account expiration. If you run chage -l USERNAME, you'll find that there might be other pieces of information that you want to extract as well.

    Hope this helps,

    Mike

  3. #3
    Just Joined!
    Join Date
    Mar 2010
    Posts
    2
    Much thanks - just what I wanted - I thought that chage only gave info about password aging, I am corrected.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...