Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- system("NET SESSION > C:\\sessions.txt");
- open FILE, "< C:\\sessions.txt" or die $!;
- my $name;
- my %userCount = ();
- my $userComputer = "";
- my $line = 0;
- my $maxopen = 150;
- while (<FILE>)
- {
- next if ($line++) < 4;
- my @columns = split(/ {2,}/);
- $userCount{$columns[1]} = $columns[2] +1;
- }
- foreach my $user(keys %userCount)
- {
- if ( $userCount{$user} > $maxopen )
- {
- my $filesopen = ($userCount{$user} -1);
- # print "* WARNING: $user has exceeded $maxopen file handles!\n";
- use MIME::Lite;
- use MIME::Base64;
- use Authen::SASL;
- my $message = MIME::Lite->new(
- From => 'admin@server.com',
- To => 'admin@email.com',
- Subject => "WARNING: Max open files on file server exceeded by $user",
- Encoding => 'base64',
- Data => "$user has exceeded $maxopen open files on the file server. They had $filesopen files open!\n"
- );
- MIME::Lite->send('smtp', 'yoursmtpserver.com', AuthUser=>"someuser", AuthPass=>"somepass");
- $message->send;
- $line = 0;
- seek(FILE, 0, 0);
- while (<FILE>)
- {
- next if ($line++) < 4;
- my @columns2 = split(/ {2,}/);
- if (!($columns2[1] cmp $user))
- {
- $userComputer = $columns2[0];
- last;
- }
- }
- exit if (!($userComputer cmp ""));
- # At this point, a user has exceeded the $maxopen files, and the following is true:
- # $user = the user name of the offender
- # $userComputer = the \\ computer address or name of the offending computer
- # $filesopen = the amount of files they had open
- # Do other activities here, possibly run psexec to disconnect mapped network drives?
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement