hux has asked for the wisdom of the Perl Monks concerning the following question:

Hiya Monks, All the user accounts on my box have an expiry date. I need a script to find out whether the account has expired, and if it has, delete it. It sounds simple, but so far i have had no luck. I hope one of you lot might be able to help. Thanks

Replies are listed 'Best First'.
Which operating system?
by cebrown (Pilgrim) on Aug 17, 2002 at 14:07 UTC
    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!

      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)