...the problem I have with this approach (and with the use of who(1)) is that their output is not predictable. Some people still use the BSD version of ps(1), some people use the SysV version, and some use the GNU version. I presume that on Solaris, you're using the SysV version unless you've updated your path.

Given that assumption, it is possible to use Perl easily enough to parse the output and give you the identities of the processes you hope to kill. And that would look a lot like the classic shell script that does this task.

I keep thinking (as I write this) that there ought to be a nice one-liner that does the trick. Perhaps I'll work it out.

---v

Well, I took a crack at it, but the only improvements I was able to offer is an invocation of ps(1) that renders the output a little more predicatably.

Here's the code:

#!/usr/bin/perl $myself = "student"; chomp ($mytty = `tty`); # gets: /dev/pts/5 $mytty =~ s/.dev.//; # gets: pts/5 =preview We'll run the command: ps -u $myself -o 'pid,tty' It will produce output like this: PID TT 419 pts/3 401 pts/3 398 ? 399 pts/3 437 ? 479 pts/5 513 pts/5 1175 ? =cut @lines = split /\n/, `ps -u $myself -o 'pid,tty'`; shift @lines; # gets rid of header line foreach $entry (@lines) { ($pid, $term) = $entry =~ /^\D*(\d+)\s+(\S+)/; next if ($term =~ /^[?]/ || $term eq $mytty); print "kill 9, $pid\n"; # for testing # kill 9, $pid; # production version }

With light testing on this system (sol8,perl v5.005), it gave the results I was hoping for. I don't know if there are some anomalous listings that might have to be accounted for.

But you will note that it finds processes with a TTY other than the current one, and kills them all. It would be better to kill only the process group leader and that would cause the others to be killed by init.

YMMV


In reply to Re: Re: Killing multiple logins. by agentv
in thread Killing multiple logins. by DigitalKitty

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.