Difference between revisions of "IdleUsers"

From Pickwiki
Jump to navigationJump to search
m
(No difference)

Revision as of 19:15, 12 February 2008

HomePage>>SourceCode>>PerlSource

This script shows a list of terminals that have not sent or received a character in the last xx minutes. It's useful for enforcing license compliance - put it on a menu somewhere and let your users know it's there. They suddenly become self-policing :-)

#!/usr/bin/perl
# 09/13/2000 Ian  Show pty's with no activity in the last 30 minutes

use File::stat;
use Getopt::Std;

getopt("c:");
if ($opt_c) {
   $cutoff = $opt_c;
} else {
   $cutoff = 30;
}

open (LISTUSER, "listuser|") || die "Cannot open listuser command: $!\n";

while (<LISTUSER>) {
   ($x, $x, $x, $user, $x, $pty, $x) = split(" ");
   if ($pty =~ /pts/) {
      $inode = stat("/dev/$pty");
      $mtime = $inode->mtime;
      $idle = int((time() - $mtime) / 60);
      if ($idle > $cutoff) {write;}
   }
}

format =
@<<<<<<<<< logged on to /dev/@<<<<<< has been idle for @#### minutes
$user, $pty, $idle
.