Created
December 21, 2012 09:09
-
-
Save klang/4351644 to your computer and use it in GitHub Desktop.
A simple little script to observe selected users activity on the system. When conducting training sessions, it's sometimes necessary to have your mother watching over you ..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
@users = ( 'klang' ); | |
my $procs = qx/ps -ef/; | |
#my $login = qx/last/; | |
foreach my $user (@users) { | |
while ($procs =~ m/^ *(\w*).+ .:.. (.+)$/gm) { | |
my $usr = $1; | |
my $proc = $2; | |
next if $procs !~ m/$user/; | |
next if $usr =~ m/root|daemon|nobody/; | |
# next if &dontwatch($proc); | |
$watch{$usr}{$proc}++; | |
# print "$usr -> $proc\n"; | |
} | |
} | |
foreach my $user (@users) { | |
my $login = qx/last -n 5 $user/; | |
$watch{$user}{'login'} = $login; | |
} | |
foreach my $user (keys %watch) { | |
$text = "---- Sessions for $user "; | |
print $text."-" x (74-length($text)).$/; | |
foreach my $proc (keys %{$watch{$user}}) { | |
next if $proc eq 'login'; | |
if ($proc =~ m/$0/ && $user ne $ENV{'USER'}) { print "$user is watching you watching him!\n"} | |
print "$user\t".$watch{$user}{$proc}."\t$proc\n"; | |
} | |
print $watch{$user}{'login'}; | |
print "-" x 74 . $/.$/; | |
} | |
sub dontwatch{ | |
my $proc = shift; | |
return 1 if $proc =~ m/cron|keyserv|ypbin|lockd|automountd|syslogd|rpcbind|sshd|devfsevent | |
d|statd|ttymon|sac|sleep|devfsadmd|inetd|vold|pageout/; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment