in reply to Detecting Expired User Accounts

If you are running *nix you can use User::pwent to find the expiration date.

On Windows, I would have to think there's something in Win32::AdminMisc that could help you.

Have fun!

Replies are listed 'Best First'.
Re: Which operating system?
by hux (Novice) on Aug 17, 2002 at 14:12 UTC
    Hi, its a *nix box. How would i put User::pwent into a script? also, is that part of perl or is it an additional module? Do you know any way of doing it without add. modules? Thanks
      Using a CPAN module is really quite easy, especially one that is already included in the standard Perl distro, such as User::pwent:
      use strict; use User::pwent; my $user = shift; my $pw = getpwnam($user) or die "No user '$user'"; print "'$user' has", $pw->expire ? ' ' : ' not ', "expired\n" ;

      "Do you know any way of doing it without add. modules?"

      Check out the built-in function getpwent, but try the module out first. It won't bite. ;)

      p.s.
      I found this information by issuing the following two commands in a terminal:

      1. perldoc User::pwent
      2. perldoc -f getpwent

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

        This may be flavour dependent, but in my experience expire is usually in epoch seconds, so in addition to testing for truth (to see if the account has an expire time) you need to also compare against time().

        use strict; use User::pwent; while ( my $user = getpwent ) { if ( $user->expire && $user->expire <= time ) { printf "%s expired (%s)\n", $user->name, scalar(localtime($user->expire)); } }

            --k.


        <tongue-in-cheek>

        And, of course, the keyword "pwent" is the first thing that pops into your head when thinking about User Accounts:)

        </tongue-in-cheek>


        What's this about a "crooked mitre"? I'm good at woodwork!
        hi there, thanks for your time. I tried it using your script but regardless of whether the account has expired or not - it tells me that the account has not expired. Any ideas? Thanks