Alwanza Home Extraordin-Air Team Final Project Linux Course Home
#!/usr/bin/perl

#   written by Rebel 7/02
#
#   Usage:   ./chk4chngs.pl
#

$base = "/";

chomp(@dir = `ls -1A "$base"`);
#
#   The plan is to make a list of all the:
#
#    a)   the files modified (or created)in the last 24 hours (1440 minutes)
#    b)   the links modified (or created)in the last 24 hours
#    c)   the directories modified (or created)in the last 24 hours unless the
#         directory is changed by the addition of a newly created (or recently
#         modified) file or link
#
#            NOTE: directories are modified only when they are created or
#                   when a file is added or deleted from that directory
#                   (not when files in the directory are changed)
#
$dirmods = 0;
for ( $i=0; $i <= $#dir; $i++ )
{
#
#  the /proc filesystem isn't real, so there is no reason to list it
#
    if ( $dir[$i] ne "proc" )
    {
#
#  put all the modified directories in @dname
#
       chomp ( @dname = `find "$base$dir[$i]" -mmin -1445 -type d -print`);
#
#  put all the modified files in @fname
#
       chomp ( @fname = `find "$base$dir[$i]" -mmin -1445 -type f -print`);
#
#  put all the modified links in @lname
#
       chomp ( @lname = `find "$base$dir[$i]" -mmin -1445 -type l -print`);

#
#  list all the modified files in $dir[$i] to STDOUT
#
       for ( $j=0; $j <= $#fname; $j++ )
       {
          print "$fname[$j]\n";
       }
#
#  list all the modified links in $dir[$i] to STDOUT
#
       for ( $j=0; $j <= $#lname; $j++ )
       {
          print "$lname[$j]\n";
       }
#
#  find modified (or new) directories with no modified files or links
#
       for ( $k=0; $k <= $#dname; $k++ )
       {
          $icnt = 0;
#
#  check for modified files
#
          for ( $j=0; $j <= $#fname; $j++ )
          {
             $fname[$j] =~ /$dname[$k](.*)/;
             if ( $1 ne "" )
             {
                  ++$icnt;
             }
          }
#
#  check for modified links
#
         for ( $j=0; $j <= $#lname; $j++ )
          {
             $lname[$j] =~ /$dname[$k](.*)/;
             if ( $1 ne "" )
             {
                  ++$icnt;
             }
          }
          if ( $icnt == 0 )
          {
             $dmodname[$dirmods++] = $dname[$k];
          }
       }
    }
print "#####      Directory only mod\'s\n";
}

#
#  list all the modified directories that have no created (or modified) files
#   or links in them to STDOUT
#
for ( $i=0; $i <= $#dmodname; $i++ )
{
    print "$dmodname[$i]\n";
}