#!/opt/bin/perl # ######################################################################### # # # Program to monitor files and to notify any changes to the user's TTY # # # ######################################################################### # # # Version 1.0 - Written 01.03.96 by Steffen Beyer # # # ######################################################################### # # # Copyright (C) 1995 by software design & management GmbH & Co. KG # # # ######################################################################### # Configure here the name(s) and owner(s) of the file(s) to monitor: $path = '/u/sysadm'; # (This is the common path for the following files. It may be left empty # if the files are specified with absolute paths.) push(@files, 'AL'); push(@users, 'alex'); push(@files, 'AS'); push(@users, 'schnagl'); push(@files, 'CB'); push(@users, 'bach'); push(@files, 'CH'); push(@users, 'joker'); push(@files, 'DB'); push(@users, 'dabe'); push(@files, 'HB'); push(@users, 'hebu'); push(@files, 'JP'); push(@users, 'pichel'); push(@files, 'KF'); push(@users, 'happy'); push(@files, 'MF'); push(@users, 'marfil'); push(@files, 'MS'); push(@users, 'blacky'); push(@files, 'RSE'); push(@users, 'rse'); push(@files, 'SB'); push(@users, 'sb'); push(@files, 'SH'); push(@users, 'susanne'); push(@files, 'TT'); push(@users, 'tommy'); push(@files, 'UB'); push(@users, 'uwe2'); push(@files, 'WW'); push(@users, 'wolfgang'); push(@files, 'XW'); push(@users, 'wunix'); # Some defaults: $version = 'version 1.0'; $self = $0; $self =~ s!^.*/!!; # Determine user's ID numbers: for ( $i = 0; $i <= $#users; $i++ ) { $user = $users[$i]; if (($uid) = (getpwnam($user))[2]) { $uids[$i] = $uid; } else { $uids[$i] = ''; } } # Loop forever: while (1) { for ( $i = 0; $i <= $#files; $i++ ) { $monfile = $files[$i]; $tagfile = "$monfile.$self"; $userid = $uids[$i]; # Check for changes in the file to monitor: if (-f "$path/$tagfile") { if (-f "$path/$monfile") { $tag = ''; unless (open(TAGFILE, "<$path/$tagfile")) { warn "$self: can't read file '$path/$tagfile': $!\n"; next; } while () { chop; if (/^\d+$/) { $tag = $_; last; } } close(TAGFILE); if ($tag eq '') { warn "$self: wrong contents in file '$path/$tagfile'!\n"; next; } $len = -s "$path/$monfile"; if ($len != $tag) { &update; if ($len > $tag) { $text = "$self: new preport in folder '$monfile'!"; ¬ify; } # else # { # $text = "$self: file '$monfile' waned!"; # ¬ify; # } } # else # { # $text = "$self: file '$monfile' didn't change."; # ¬ify; # } } else { unlink("$path/$tagfile"); $text = "$self: file '$monfile' disappeared!"; ¬ify; } } else { if (-f "$path/$monfile") { $len = -s "$path/$monfile"; &update; # $text = "$self: new file '$monfile'!"; # ¬ify; } else { $text = "$self: no file '$monfile'!"; ¬ify; } } } sleep(5); } exit 0; sub update { unless (open(TAGFILE, ">$path/$tagfile")) { warn "$self: can't write file '$path/$tagfile': $!\n"; return; } print TAGFILE "$len\n"; close(TAGFILE); } sub notify { # Read in all the devices currently used by the system, determine # the terminals the user is connected to and send a message to it: unless (opendir(DEV, "/dev")) { warn "$self: can't read directory '/dev': $!\n"; return; } while ($terminal = readdir(DEV)) { next if ($terminal eq '.'); next if ($terminal eq '..'); next unless ($terminal =~ /^tty/i); next unless (($uid) = (stat("/dev/$terminal"))[4]); if ($uid == $userid) { if (open(TEXT, ">/dev/$terminal")) { print TEXT "\n\n\n$text\n\n\n"; close(TEXT); } } } closedir(DEV); } __END__