Advertisement
Guest User

Untitled

a guest
Oct 17th, 2013
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.89 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. system("NET SESSION > C:\\sessions.txt");
  4.  
  5. open FILE, "< C:\\sessions.txt" or die $!;
  6.  
  7. my $name;
  8. my %userCount = ();
  9. my $userComputer = "";
  10. my $line = 0;
  11. my $maxopen = 150;
  12.  
  13. while (<FILE>)
  14. {
  15.         next if ($line++) < 4;
  16.         my @columns = split(/ {2,}/);
  17.  
  18.         $userCount{$columns[1]} = $columns[2] +1;
  19.  
  20. }
  21.  
  22. foreach my $user(keys %userCount)
  23. {
  24.         if ( $userCount{$user} > $maxopen )
  25.         {
  26.                 my $filesopen = ($userCount{$user} -1);
  27. #               print "* WARNING: $user has exceeded $maxopen file handles!\n";
  28.                 use MIME::Lite;
  29.                 use MIME::Base64;
  30.                 use Authen::SASL;
  31.  
  32.                 my $message = MIME::Lite->new(
  33.                         From    => 'admin@server.com',
  34.                         To      => 'admin@email.com',
  35.                         Subject => "WARNING: Max open files on file server exceeded by $user",
  36.                         Encoding => 'base64',
  37.                         Data => "$user has exceeded $maxopen open files on the file server.  They had $filesopen files open!\n"
  38.                 );
  39.  
  40.                 MIME::Lite->send('smtp', 'yoursmtpserver.com', AuthUser=>"someuser", AuthPass=>"somepass");
  41.                 $message->send;
  42.  
  43.         $line = 0;
  44.  
  45.         seek(FILE, 0, 0);
  46.  
  47.         while (<FILE>)
  48.         {
  49.             next if ($line++) < 4;
  50.  
  51.             my @columns2 = split(/ {2,}/);
  52.  
  53.             if (!($columns2[1] cmp $user))
  54.             {                      
  55.                 $userComputer = $columns2[0];
  56.                 last;
  57.             }
  58.         }
  59.  
  60.         exit if (!($userComputer cmp ""));
  61.  
  62.         # At this point, a user has exceeded the $maxopen files, and the following is true:
  63.         #    $user = the user name of the offender
  64.         #    $userComputer = the \\ computer address or name of the offending computer
  65.         #    $filesopen = the amount of files they had open
  66.  
  67.         # Do other activities here, possibly run psexec to disconnect mapped network drives?
  68.         }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement