C
Clifford Bracht
I'm tring to write a script that verifies if the time of the last
modification is more recent than the time of the last access. Because
I would like to know when any action (save, add text, delete text
etc.) has occurred to the file. But I think that I have some syntax
problems with either my if statement or the stat function becuase my
atime and mtime are the same number no matter what kind of changes I
make to the file. Do any of you guys have any solutions or advice
for what I have here:
Thanks in Advance
#!/usr/bin/perl -w
#perl -w
use strict;
my $filename = "C:/temp/test.txt";
open FILEHANDLE, $filename or die "Cannot open $filename,
err=\"$!\"\n";
#While file is open do the following...
while (<FILEHANDLE>)
{
#Assign $atime to access time & $mtime to modification time
#$atime and $mtime are refreshed after each time the info is gathered.
my $atime = (stat ($filename))[8] || die "Sorry, cannot stat! \n";
my $mtime = (stat ($filename))[9] || die "Sorry, cannot stat! \n";
#test output to see what is that is going to be compared.
print "$atime \n";
print "$mtime \n";
#Check to see if modification time is more recent then the time of
last access.
if ($mtime == $atime) #$mtime = $ctime)
{
print "$filename is OK! \n";
}
else
{
print "$filename has been modified. \n";
}
}
close FILEHANDLE;
print "$filename is done testing. \n";
modification is more recent than the time of the last access. Because
I would like to know when any action (save, add text, delete text
etc.) has occurred to the file. But I think that I have some syntax
problems with either my if statement or the stat function becuase my
atime and mtime are the same number no matter what kind of changes I
make to the file. Do any of you guys have any solutions or advice
for what I have here:
Thanks in Advance
#!/usr/bin/perl -w
#perl -w
use strict;
my $filename = "C:/temp/test.txt";
open FILEHANDLE, $filename or die "Cannot open $filename,
err=\"$!\"\n";
#While file is open do the following...
while (<FILEHANDLE>)
{
#Assign $atime to access time & $mtime to modification time
#$atime and $mtime are refreshed after each time the info is gathered.
my $atime = (stat ($filename))[8] || die "Sorry, cannot stat! \n";
my $mtime = (stat ($filename))[9] || die "Sorry, cannot stat! \n";
#test output to see what is that is going to be compared.
print "$atime \n";
print "$mtime \n";
#Check to see if modification time is more recent then the time of
last access.
if ($mtime == $atime) #$mtime = $ctime)
{
print "$filename is OK! \n";
}
else
{
print "$filename has been modified. \n";
}
}
close FILEHANDLE;
print "$filename is done testing. \n";