<?xml version="1.0"?><!-- generator="bbPress" -->

<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
>

<channel>
<title>Windows Perl Scripting Forums &#187; Topic: Logegd users script</title>
<link>http://www.roth.net/forums/</link>
<description>Windows Perl Scripting Forums &#187; Topic: Logegd users script</description>
<language>en</language>
<pubDate>Thu, 23 May 2013 08:08:50 +0000</pubDate>

<item>
<title>Dave on "Logegd users script"</title>
<link>http://www.roth.net/forums/topic.php?id=8#post-37</link>
<pubDate>Sun, 13 Aug 2006 17:58:20 +0000</pubDate>
<dc:creator>Dave</dc:creator>
<guid isPermaLink="false">37@http://www.roth.net/forums/</guid>
<description>I am not sure what issues you are running into, but your script works fine for me as long as I change the server name.&#60;br /&#62;
However with a slight rewrite of code it is working mightly well. This version takes options: [-s SERVER] [-u USER1 [-u USER2 [...]]]&#60;br /&#62;
&#60;br /&#62;
&#60;br /&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
#!/usr/local/bin/perl -w &#60;br /&#62;
#-*-perl-*- &#60;br /&#62;
# &#60;br /&#62;
use strict;&#60;br /&#62;
use Win32API&#38;#58;&#38;#58;Net; &#60;br /&#62;
use vars qw &#38;#40; %UserInfo @WhoList &#38;#41;; &#60;br /&#62;
use Win32&#38;#58;&#38;#58;NetAdmin; &#60;br /&#62;
use Getopt&#38;#58;&#38;#58;Long;&#60;br /&#62;
&#60;br /&#62;
my &#38;#40;$VERSION&#38;#41; = '$Revision&#38;#58; 1.0 $' =~ /&#38;#40;&#38;#91;.\d&#38;#93;+&#38;#41;/; &#60;br /&#62;
&#60;br /&#62;
my $warnings = 0; &#60;br /&#62;
&#60;br /&#62;
# Print a usuage message on a unknown option. &#60;br /&#62;
&#60;br /&#62;
$SIG &#38;#123;__WARN__&#38;#125; = sub &#38;#123; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;if &#38;#40;substr &#38;#40;$_ &#38;#91;0&#38;#93;, 0, 14&#38;#41; eq &#38;quot;Unknown option&#38;quot;&#38;#41; &#38;#123;die &#38;quot;Usage&#38;quot;&#38;#125;; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;require File&#38;#58;&#38;#58;Basename; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;$0 = File&#38;#58;&#38;#58;Basename&#38;#58;&#38;#58;basename &#38;#40;$0&#38;#41;; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;$warnings = 1; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;warn &#38;quot;$0&#38;#58; @_&#38;quot;; &#60;br /&#62;
&#38;#125;; &#60;br /&#62;
&#60;br /&#62;
$SIG &#38;#123;__DIE__&#38;#125; = sub &#38;#123; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;require File&#38;#58;&#38;#58;Basename; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;$0 = File&#38;#58;&#38;#58;Basename&#38;#58;&#38;#58;basename &#38;#40;$0&#38;#41;; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;if &#38;#40;substr &#38;#40;$_ &#38;#91;0&#38;#93;, 0, 5&#38;#41; eq &#38;quot;Usage&#38;quot;&#38;#41; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;&#38;#123; &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; die &#38;lt;&#38;lt;EOF; &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp;$0 &#38;#40;NT Perl bin utils&#38;#41; $VERSION &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp;$0 &#38;#91;-s server&#38;#93; &#38;#91;-u userid &#38;#91;-u ...&#38;#93; &#38;#93; &#38;#91; -h &#38;#93; &#60;br /&#62;
EOF&#60;br /&#62;
&#38;nbsp; &#38;nbsp;&#38;#125; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;die &#38;quot;$0&#38;#58; @_&#38;quot;; &#60;br /&#62;
&#38;#125;; &#60;br /&#62;
&#60;br /&#62;
my %Config = &#38;#40;&#60;br /&#62;
&#38;nbsp; server =&#38;gt; &#38;quot;&#38;quot;&#60;br /&#62;
&#38;#41;;&#60;br /&#62;
Configure&#38;#40; \%Config &#38;#41;;&#60;br /&#62;
if&#38;#40; $Config&#38;#123;help&#38;#125; &#38;#41;&#60;br /&#62;
&#38;#123;&#60;br /&#62;
&#38;nbsp; &#38;nbsp; die &#38;quot;Usage&#38;quot;;&#60;br /&#62;
&#38;#125;&#60;br /&#62;
&#60;br /&#62;
my $Level = &#38;quot;11&#38;quot;; # make UserGetInfo&#38;#40;&#38;#41; return lastLogon &#60;br /&#62;
my $Filter = &#38;quot;0&#38;quot;; # I do not know what this does and why &#60;br /&#62;
# it must be numeric. &#60;br /&#62;
&#60;br /&#62;
if&#38;#40; scalar $Config&#38;#123;users&#38;#125; &#38;#41;&#60;br /&#62;
&#38;#123;&#60;br /&#62;
&#38;nbsp; &#38;nbsp;foreach my $User &#38;#40; @&#38;#123;$Config&#38;#123;users&#38;#125;&#38;#125; &#38;#41;&#60;br /&#62;
&#38;nbsp; &#38;nbsp;&#38;#123;&#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; push&#38;#40; @WhoList, $User&#38;#41; if&#38;#40; Win32&#38;#58;&#38;#58;NetAdmin&#38;#58;&#38;#58;UsersExist&#38;#40; $Config&#38;#123;server&#38;#125;, $User &#38;#41; &#38;#41;;&#60;br /&#62;
&#38;nbsp; &#38;nbsp;&#38;#125;&#60;br /&#62;
&#38;#125;&#60;br /&#62;
else&#60;br /&#62;
&#38;#123;&#60;br /&#62;
&#38;nbsp; &#38;nbsp;Win32&#38;#58;&#38;#58;NetAdmin&#38;#58;&#38;#58;GetUsers&#38;#40; $Config&#38;#123;server&#38;#125;, $Level, \@WhoList &#38;#41; or die &#38;quot;$^E\n&#38;quot;;&#60;br /&#62;
&#38;#125;&#60;br /&#62;
&#60;br /&#62;
foreach my $UserName &#38;#40; sort&#38;#40; &#38;#123; lc $a cmp lc $b&#38;#125; @WhoList &#38;#41; &#38;#41;&#60;br /&#62;
&#38;#123; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;printf&#38;#40; &#38;quot;%- 26s Last login&#38;#58; %s\n&#38;quot;, $UserName, UserGetInfo&#38;#40; $UserName &#38;#41; &#38;#41;;&#60;br /&#62;
&#38;#125; &#60;br /&#62;
&#60;br /&#62;
sub UserGetInfo &#60;br /&#62;
&#38;#123; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;my $userid = shift &#38;#40; @_ &#38;#41;; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;my $length = 25 - length $userid; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;my $last; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;if &#38;#40; Win32API&#38;#58;&#38;#58;Net&#38;#58;&#38;#58;UserGetInfo &#38;#40; $Config&#38;#123;server&#38;#125;, $userid, $Level, \%UserInfo &#38;#41; &#38;#41; &#38;#123; &#60;br /&#62;
&#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; if &#38;#40; 0 == $UserInfo&#38;#123;lastLogon&#38;#125;&#38;nbsp; &#38;#41; &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;#123; &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp;$last = &#38;quot;never&#38;quot;; &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;#125; &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; else &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;#123; &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp;$last = localtime &#38;#40; $UserInfo&#38;#123;lastLogon&#38;#125; &#38;#41;; &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;#125; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;&#38;#125; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;else &#60;br /&#62;
&#38;nbsp; &#38;nbsp;&#38;#123; &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; $last = &#38;quot;unknown&#38;quot;; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;&#38;#125; &#60;br /&#62;
&#38;nbsp; &#38;nbsp;return &#38;#40; $last &#38;#41;; &#60;br /&#62;
&#38;#125;&#60;br /&#62;
&#60;br /&#62;
sub Configure&#60;br /&#62;
&#38;#123;&#60;br /&#62;
&#38;nbsp; &#38;nbsp; my&#38;#40; $Config &#38;#41; = @_;&#60;br /&#62;
&#38;nbsp; &#38;nbsp; my $Result;&#60;br /&#62;
&#38;nbsp; &#38;nbsp; Getopt&#38;#58;&#38;#58;Long&#38;#58;&#38;#58;Configure&#38;#40; &#38;quot;prefix_pattern=&#38;#40;-&#124;\/&#38;#41;&#38;quot; &#38;#41;;&#60;br /&#62;
&#38;nbsp; &#38;nbsp; $Result = GetOptions&#38;#40; $Config, &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; qw&#38;#40; &#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; server&#124;s=s&#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; users&#124;u=s@&#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; help&#124;?&#60;br /&#62;
&#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;nbsp; &#38;#41; &#38;#41;;&#60;br /&#62;
&#60;br /&#62;
&#38;nbsp; &#38;nbsp; $Config-&#38;gt;&#38;#123;help&#38;#125; = 1 unless&#38;#40; $Result &#38;#41;;&#60;br /&#62;
&#38;#125;&#60;br /&#62;
&#60;br /&#62;
&#60;/code&#62;&#60;/p&#62;</description>
</item>
<item>
<title>akearins on "Logegd users script"</title>
<link>http://www.roth.net/forums/topic.php?id=8#post-15</link>
<pubDate>Tue, 25 Jul 2006 18:46:51 +0000</pubDate>
<dc:creator>akearins</dc:creator>
<guid isPermaLink="false">15@http://www.roth.net/forums/</guid>
<description>Below is a script to allow a user see the last users logged onto a host.&#60;br /&#62;
However the environment it will be run in (university) needs to read the user log form a particular host (entered by user e.g. Lab.ABC) and display all users in that log.&#60;br /&#62;
At prsenet it only dispalys this information form the host machine it is running from. Help appreciated&#60;br /&#62;
&#60;br /&#62;
&#60;br /&#62;
&#60;br /&#62;
#!/usr/local/bin/perl -w&#60;br /&#62;
#-*-perl-*-&#60;br /&#62;
#&#60;br /&#62;
&#60;br /&#62;
use strict;&#60;br /&#62;
use Win32API::Net;&#60;br /&#62;
use vars qw ( %UserInfo @WhoList );&#60;br /&#62;
use Win32::NetAdmin;&#60;br /&#62;
&#60;br /&#62;
my ($VERSION) = '$Revision: 1.0 $' =~ /([.\d]+)/;&#60;br /&#62;
&#60;br /&#62;
my $warnings = 0;&#60;br /&#62;
&#60;br /&#62;
# Print a usuage message on a unknown option.&#60;br /&#62;
&#60;br /&#62;
$SIG {__WARN__} = sub {&#60;br /&#62;
    if (substr ($_ [0], 0, 14) eq &#38;quot;Unknown option&#38;quot;) {die &#38;quot;Usage&#38;quot;};&#60;br /&#62;
    require File::Basename;&#60;br /&#62;
    $0 = File::Basename::basename ($0);&#60;br /&#62;
    $warnings = 1;&#60;br /&#62;
    warn &#38;quot;$0: @_&#38;quot;;&#60;br /&#62;
};&#60;br /&#62;
&#60;br /&#62;
$SIG {__DIE__} = sub {&#60;br /&#62;
    require File::Basename;&#60;br /&#62;
    $0 = File::Basename::basename ($0);&#60;br /&#62;
    if (substr ($_ [0], 0,  5) eq &#38;quot;Usage&#38;quot;) {&#60;br /&#62;
        die &#38;lt;&#38;lt;EOF;&#60;br /&#62;
$0 (NT Perl bin utils) $VERSION&#60;br /&#62;
$0 [ userid ] [ -h ]&#60;br /&#62;
EOF&#60;br /&#62;
    }&#60;br /&#62;
    die &#38;quot;$0: @_&#38;quot;;&#60;br /&#62;
};&#60;br /&#62;
&#60;br /&#62;
die &#38;quot;Usage&#38;quot; if ( $ARGV[0] &#38;amp;&#38;amp; $ARGV[0] eq &#38;quot;-h&#38;quot; );&#60;br /&#62;
&#60;br /&#62;
my $Server = &#38;quot;&#38;quot;;              # localhost only&#60;br /&#62;
my $Level  = &#38;quot;11&#38;quot;;            # make UserGetInfo() return lastLogon&#60;br /&#62;
my $Filter = &#38;quot;0&#38;quot;;             # I do not know what this does and why&#60;br /&#62;
                              # it must be numeric.&#60;br /&#62;
&#60;br /&#62;
Win32::NetAdmin::GetUsers (&#60;br /&#62;
      $Server,&#60;br /&#62;
      $Filter,&#60;br /&#62;
      \@WhoList&#60;br /&#62;
     ) &#60;br /&#62;
  or die &#38;quot;$^E\n&#38;quot;&#60;br /&#62;
  unless $ARGV[0];&#60;br /&#62;
&#60;br /&#62;
if ( exists $ARGV[0] ) {&#60;br /&#62;
    $WhoList[0] = $ARGV[0] &#60;br /&#62;
      if Win32::NetAdmin::UsersExist (&#60;br /&#62;
          $Server,&#60;br /&#62;
          $ARGV[0]&#60;br /&#62;
         ) &#60;br /&#62;
      or exit;&#60;br /&#62;
}&#60;br /&#62;
&#60;br /&#62;
foreach my $UserName ( @WhoList ) {&#60;br /&#62;
    my (&#60;br /&#62;
 $LastLogin,&#60;br /&#62;
 $NameLength&#60;br /&#62;
       ) = UserGetInfo( $UserName );&#60;br /&#62;
&#60;br /&#62;
    printf &#38;quot;%s %$ {NameLength}s: %s\n&#38;quot;, $UserName, &#38;quot;Last login&#38;quot;, $LastLogin;&#60;br /&#62;
}&#60;br /&#62;
&#60;br /&#62;
sub UserGetInfo {&#60;br /&#62;
    my $userid = shift ( @_ );&#60;br /&#62;
    my $length = 25 - length $userid;&#60;br /&#62;
    my $last;&#60;br /&#62;
    if ( Win32API::Net::UserGetInfo (&#60;br /&#62;
         $Server,&#60;br /&#62;
         $userid,&#60;br /&#62;
         $Level,&#60;br /&#62;
         \%UserInfo&#60;br /&#62;
        ) ) {&#60;br /&#62;
&#60;br /&#62;
 if ( $UserInfo{lastLogon} == 0 ) {&#60;br /&#62;
     $last = &#38;quot;never&#38;quot;;&#60;br /&#62;
 }&#60;br /&#62;
 else {&#60;br /&#62;
     $last = localtime ( $UserInfo{lastLogon} );&#60;br /&#62;
 }&#60;br /&#62;
    }&#60;br /&#62;
    else {&#60;br /&#62;
     $last = &#38;quot;unknown&#38;quot;;&#60;br /&#62;
 }&#60;br /&#62;
    return ( $last, $length );&#60;br /&#62;
}</description>
</item>

</channel>
</rss>
