LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-02-2006, 10:40 AM   #1
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Rep: Reputation: 31
Perl: Check if file has been created in the last 10 minutes


Hello. I have a file located at /some/path/to/file. I need my perl script to check if this file has been created in the last 10 minutes. How can this be accomplished ?
 
Old 06-02-2006, 10:52 AM   #2
introuble
Member
 
Registered: Apr 2004
Distribution: Debian -unstable
Posts: 700

Original Poster
Rep: Reputation: 31
Never mind. Figured it out. Using stat() and time()
 
Old 06-02-2006, 10:58 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi (again),

Give stat and time a try:
Code:
#!/usr/bin/perl

use strict;
use warnings;

# To get time
my $currDate = time;

my $thisFile = "/path/to/file.name";

my $dev;
my $ino;
my $mode;
my $nlink;
my $uid;
my $gid;
my $rdev;
my $size;
my $atime;
my $mtime;
my $ctime;
my $blksize;
my $blocks;

# The get file info
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat $thisFile;


print $dev ."\n";
print $ino ."\n";
print $mode ."\n";
print $nlink ."\n";
print $uid ."\n";
print $gid ."\n";
print $rdev ."\n";
print $size ."\n";
print $atime ."\n";
print $mtime ."\n";
print $ctime ."\n";
print $blksize ."\n";
print $blocks ."\n";
print "\n";
print $currDate . "\n";
Both give the same timeformat, should be easy to add/subtrack 10 minutes.

Hope this helps.
 
  


Reply

Tags
perl, stat


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find out if a file was modified in the last 2 minutes.... cricos Programming 5 04-06-2005 02:57 PM
Linux Executable File Help (created from a .c file) MattG1981 Linux - Newbie 7 06-06-2004 04:54 PM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 05:07 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
Please check this program(perl) for me! Rex_chaos Programming 2 04-25-2002 06:56 PM


All times are GMT -5. The time now is 07:51 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration