LinuxQuestions.org
Register a domain and help support LQ
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
 
LinkBack Search this Thread
Old 10-23-2009, 04:00 PM   #1
chackercon
Member
 
Registered: Jan 2008
Location: Oklahoma
Distribution: Slackware, QNX, Centos 5.2, Dream Linux, BackTrack, Fedora
Posts: 53

Rep: Reputation: 18
Perl script to look at a directory for a new file


Ok, I am new to programming but I am a quick study. I have this script working.

#!/usr/bin/perl
@info=stat("/share/") or die "Can't stat share $!";
while (1) {
@newinfo=stat("/share/") or die "Can't stat share $!";
@what=qw(Device Inum Mode Links Owner Group Rdev Size Atime Mtime Ctime PBlock Blocks);
$x=0;
while (scalar(@info) > $x) {
system("/bin/echo $what[$x] $info[$x] $newinfo[$x]") if ($info[$x] ne $newinfo[$x]);
$x++;
}
@info=@newinfo;
sleep 1;
}
and the output of the script when a file is created or moved is this,
Mtime 1256325955 1256327234
Ctime 1256325955 1256327234
Atime 1256326852 1256327455
Atime 1256327455 1256327464
Atime 1256327464 1256327469
Links 9 8
Mtime 1256327234 1256327475
Ctime 1256327234 1256327475
Atime 1256327469 1256327483

I instead would like to be able to get the new file name and redirect this output to a file.

I know that this is possible I just need some help getting pointed in the right direction. I don't want anyone to do it for me I want to learn and don't mind reading.

All help is welcome and Thank you in advance.

Mike
 
Old 10-23-2009, 06:56 PM   #2
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 59
First, please wrap code selections in [code][/code] tags. Second, if you're working on a Linux system, you should check out one of the inotify modules on CPAN. They give you access to the kernel's event system. A reasonably full-featured option looks to be Linux::Inotify2, but I haven't worked with it.
 
Old 10-24-2009, 04:23 PM   #3
chackercon
Member
 
Registered: Jan 2008
Location: Oklahoma
Distribution: Slackware, QNX, Centos 5.2, Dream Linux, BackTrack, Fedora
Posts: 53

Original Poster
Rep: Reputation: 18
Telemachos

Thank you for the reply, I will use the code tags from now on. Also thanks for the inotify info I had see it but did not even really give it a second thought.

Thanks
Mike
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl, Removing file from path to get directory only xemous Programming 6 09-02-2008 03:12 PM
To rename files in a directory should I use Bash script or a Perl Script ? jamtech Programming 7 01-23-2008 12:25 AM
perl: (2)No such file or directory: exec of ... xpucto Linux - Newbie 1 11-13-2007 06:21 AM
to change the directory using a perl script in linux kernel indu.a Linux - Kernel 3 11-15-2006 04:22 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 09:09 PM


All times are GMT -5. The time now is 02:44 PM.

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
Open Source Consulting | Domain Registration