#!/usr/bin/perl use strict; use Sys::Syslog; use English; my ($temp); # holds temporary data my ($mytty); # holds my tty my ($ttytype); # holds either tty or pts my ($ipaddr); # holds my ip addr my ($childpid); # holds the pid of a child process my (@w_listing); # array for output of w command delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; $ENV{PATH} = "/bin:/usr/bin"; open (FROMKID, "-|") or exec ("who", "-m") or system_log ("Can't run w +ho: $!"); if (eof FROMKID) {exit 1;} while (<FROMKID>) { if (/tty(.*?)\s/) { $mytty = "tty" . $1; $ttytype = "tty"; } elsif (/pts(.*?)\s/) { $mytty = "pts" . $1; $ttytype = "pts"; } } close FROMKID; if (defined($mytty)) { open (FROMKID, "-|") or exec ("w", "-s") or system_log ("Can't run w +: $!"); if (eof FROMKID) {exit 1;} while (<FROMKID>) { my ($w_idx); # subsript for @w_listing; $w_idx = @w_listing; $w_listing[$w_idx] = $_; } close FROMKID; foreach (@w_listing) { if (/$mytty\s.*?\b(.*?)\s/) { $ipaddr = $1; } } if (defined($ipaddr)) { foreach (@w_listing) { my ($checktty); # tty to check for d3 process if (/$ttytype(.*?)\s.*?$ipaddr/) { next if (($ttytype . $1) eq $mytty); # we don't want to kill o +urselves! $checktty = $1; open (FROMKID, "-|") or exec ("ps", "awwww") or system_log ("C +an't run ps: $!"); if (eof FROMKID) {exit 1;} while (<FROMKID>) { foreach (<FROMKID>) { if (/^ *(\d*?)\s.*?\b$checktty\s.*?d3.*?VIDEO/) { my ($killresult); $killresult = kill 15, $1; if ($killresult) { if (kill 0, $1) { $killresult = kill 1, $1; } } if ($killresult) { system_log ('PID %d has been killed successfully for % +s', $1, $ipaddr); } else { system_log ('Attempt to kill PID %d for %s failed', $1 +, $ipaddr); print "You are unable to login because there is alread +y a D3 process\n"; print "running from your IP address.\n\n"; print "Please call Example Systems for assistance.\n\n +"; print "Press <ENTER> to continue..."; my $hit_enter = <STDIN>; exit 1; } } } } close FROMKID; } } } else { print "I cannot determine my IP address.\n\n"; print "Please call Example Systems.\n\n"; print "Press <ENTER> to continue..."; system_log ("Cannot determine IP address"); my $hit_enter = <STDIN>; } } else { print "I cannot determine my tty.\n\n"; print "Please call Example Systems.\n\n"; print "Press <ENTER> to continue..."; system_log ("Cannot determine tty"); my $hit_enter = <STDIN>; } sub system_log { Sys::Syslog::setlogsock ('unix'); openlog ('onlyone', 'pid','user'); # open a channel to the syslo +gd syslog ('info', @_); closelog(); }

In reply to onlyone by BoredByPolitics

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.