in reply to Re: Which operating system?
in thread Detecting Expired User Accounts

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)

Replies are listed 'Best First'.
Re: Re: Re: Detecting Expired User Accounts
by Kanji (Parson) on Aug 17, 2002 at 20:38 UTC

    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.


Re: (jeffa) 2Re: Detecting Expired User Accounts
by BrowserUk (Patriarch) on Aug 17, 2002 at 19:19 UTC

    <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!
Re: (jeffa) 2Re: Detecting Expired User Accounts
by Anonymous Monk on Aug 17, 2002 at 15:15 UTC
    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