checking file age
am 15.01.2008 16:46:00 von stu
Can somebody provide me with a perl funcion that accepts
(full path of file, number of minutes, and operation) and checks the
last access time of a file.
For example, if I pass the following:
c:/temp/testfile 5 GT
The function will check the last access time of the file c:/temp/
testfile and see if it is greater than 5 minutes old.
If I pass c:/temp/testfile 6 LE
The function will check the last access time of the file c:/temp/
testfile and see if it is less than or equal to 6 minutes old.
If the anwer is yes I want to return 1 for TRUE else return 0 for
false.
Thanks in advance for all that answer this post
I
Re: checking file age
am 15.01.2008 16:50:50 von Paul Lalli
On Jan 15, 10:46=A0am, Stu wrote:
> Can somebody provide me with a perl funcion that accepts
> (full path of file, number of minutes, and operation) and checks
> the last access time of a file.
>
> For example, if I pass the following:
>
> c:/temp/testfile =A0 =A05 =A0 =A0 GT
>
> The function will check the last access time of the file c:/temp/
> testfile and see if it is greater than 5 minutes old.
>
> If I pass c:/temp/testfile =A0 =A06 =A0 =A0 LE
>
> The function will check the last access time of the file c:/temp/
> testfile and see if it is less than or equal to 6 minutes old.
>
> If the anwer is yes I want to return 1 for TRUE else return 0 for
> false.
>
> Thanks in advance for all that answer this post
What have you done so far? What part is causing you problems? Please
post a short but complete script that demonstrates the issue you're
having.
To find the last access time of a file in seconds, you use the -A
operator:
my $secs =3D -A $file;
To find minutes from seconds, you divide by 60
my $minutes =3D $secs / 60;
To compare a number to a given value, you use one of the numeric
comparison operators: <, >, <=3D, >=3D, ==, !=3D
To learn how to write a subroutine, you read `perldoc perlsub` by
typing those two words in a command window.
If you make an attempt to solve your own problem, people here will be
very willing to help you and show you where you might be going wrong.
Paul Lalli
Re: checking file age
am 15.01.2008 17:48:51 von rwxrxrx
Stu åé:
> Can somebody provide me with a perl funcion that accepts
> (full path of file, number of minutes, and operation) and checks the
> last access time of a file.
>
> For example, if I pass the following:
>
> c:/temp/testfile 5 GT
>
> The function will check the last access time of the file c:/temp/
> testfile and see if it is greater than 5 minutes old.
>
> If I pass c:/temp/testfile 6 LE
>
> The function will check the last access time of the file c:/temp/
> testfile and see if it is less than or equal to 6 minutes old.
>
> If the anwer is yes I want to return 1 for TRUE else return 0 for
> false.
>
> Thanks in advance for all that answer this post
>
>
>
>
>
>
> I
>
It's your homework?
Re: checking file age
am 15.01.2008 17:57:35 von stu
On Jan 15, 11:48 am, "Scott.Jo" wrote:
> Stu $B
>
>
>
> > Can somebody provide me with a perl funcion that accepts
> > (full path of file, number of minutes, and operation) and checks the
> > last access time of a file.
>
> > For example, if I pass the following:
>
> > c:/temp/testfile 5 GT
>
> > The function will check the last access time of the file c:/temp/
> > testfile and see if it is greater than 5 minutes old.
>
> > If I pass c:/temp/testfile 6 LE
>
> > The function will check the last access time of the file c:/temp/
> > testfile and see if it is less than or equal to 6 minutes old.
>
> > If the anwer is yes I want to return 1 for TRUE else return 0 for
> > false.
>
> > Thanks in advance for all that answer this post
>
> > I
>
> It's your homework?- Hide quoted text -
>
> - Show quoted text -
No it is not, just needed help with the -A for access time. All done
thanks eveyr
Re: checking file age
am 15.01.2008 19:25:12 von jurgenex
Stu wrote:
>Can somebody provide me with a perl funcion that accepts
>(full path of file, number of minutes, and operation) and checks the
>last access time of a file.
See
perldoc -f -X (you are looking for -A)
perldoc perlop (you are looking for > and <=)
jue
Re: checking file age
am 15.01.2008 19:35:06 von stu
On Jan 15, 10:50=A0am, Paul Lalli wrote:
> On Jan 15, 10:46=A0am, Stu wrote:
>
>
>
>
>
> > Can somebody provide me with a perl funcion that accepts
> > (full path of file, number of minutes, and operation) and checks
> > the last access time of a file.
>
> > For example, if I pass the following:
>
> > c:/temp/testfile =A0 =A05 =A0 =A0 GT
>
> > The function will check the last access time of the file c:/temp/
> > testfile and see if it is greater than 5 minutes old.
>
> > If I pass c:/temp/testfile =A0 =A06 =A0 =A0 LE
>
> > The function will check the last access time of the file c:/temp/
> > testfile and see if it is less than or equal to 6 minutes old.
>
> > If the anwer is yes I want to return 1 for TRUE else return 0 for
> > false.
>
> > Thanks in advance for all that answer this post
>
> What have you done so far? =A0What part is causing you problems? =A0Please=
> post a short but complete script that demonstrates the issue you're
> having.
>
> To find the last access time of a file in seconds, you use the -A
> operator:
> my $secs =3D -A $file;
>
> To find minutes from seconds, you divide by 60
> my $minutes =3D $secs / 60;
>
> To compare a number to a given value, you use one of the numeric
> comparison operators: <, >, <=3D, >=3D, ==, !=3D
>
> To learn how to write a subroutine, you read `perldoc perlsub` by
> typing those two words in a command window.
>
> If you make an attempt to solve your own problem, people here will be
> very willing to help you and show you where you might be going wrong.
>
> Paul Lalli- Hide quoted text -
>
> - Show quoted text -
Paul,
Thanks for your help but I think -A returns the value in days and not
seconds. (see below).
I am going to take the current time in secs and subtract the stat time
and that should do it for me.
File test Meaning
-r File is readable by effective uid/gid
-w File is writable by effective uid/gid.
-x File is executable by effective uid/gid.
-o File is owned by effective uid.
-R File is readable by real uid/gid.
-W File is writable by real uid/gid.
-X File is executable by real uid/gid.
-O File is owned by real uid.
-e File exists.
-z File has zero size (is empty).
-s File has nonzero size (returns size in bytes).
-f File is a plain file.
-d File is a directory.
-l File is a symbolic link.
-p File is a named pipe (FIFO), or Filehandle is a pipe.
-S File is a socket.
-b File is a block special file.
-c File is a character special file.
-t Filehandle is opened to a tty
-u File has setuid bit set.
-g File has setgid bit set.
-k File has sticky bit set.
-T File is an ASCII text file (heuristic guess).
-B File is a "binary" file (opposite of -T).
-M Script start time minus file modification time, in days.
-A Same for access time.
-C Same for inode change time (Unix, may differ for other platforms)