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

Hi
Is there a way to find and list out all the users who have logged into a machine using perl? Other than using the user manager, i was wondering if one can automate the stuff.
Thanks.

we're born with our eyes closed and our mouths wide open, and we spend our entire life trying to rectify that mistake of nature. - anonymous.

Replies are listed 'Best First'.
Re: List of Users
by Abigail-II (Bishop) on Jul 23, 2003 at 09:58 UTC
    Not really. There isn't a Perl primitive for it. "Users" is something very system specific. You could of course always use backticks, and use an appropriate command. Typical Unix commands to use: who, w and finger. But note not all systems will have these commands, and not all that have will use the same format of output. On Unix, you could also peek in /tmp/wtmp, /tmp/utmp, /tmp/wtmpx or /tmp/utmpx, depending on what's available. And who knows whether some OS has a /proc/users (>/proc/users to log everyone off... ;-)).

    What the situation is on non-Unix systems, I've no idea.

    Abigail

    P.S. Please fix your sig. You aren't closing your <i> element properly.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: List of Users
by BrowserUk (Patriarch) on Jul 23, 2003 at 13:16 UTC
    use Win32::NetAdmin qw[LoggedOnUser]; my @users; LoggedOnUsers( '', \@users ); print $_, $/ for @users;

    In general, if you working with Win32, then spending an hour or two looking through the Win32::* html pages/ pod is time well spent.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller

Re: List of Users
by NetWallah (Canon) on Jul 23, 2003 at 18:10 UTC
    Um - may I respectfully suggest to BrowserUK that it is
    use Win32::NetAdmin qw[LoggedOnUsers];
    . Notice the plural in use LoggedOnUsers;

    I feel a certain amount of glee here in being able to correct BrowserUK, but that is only because I have a great deal of respect for his postings.

      Bah! Humbug:).

      I spelt it right the second time...like most of my faculties, even my dyslexia is flakey and intermittant.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller