We help IT Professionals succeed at work.

Script to check the time stamp of a file and then move it

2xdafun
2xdafun used Ask the Experts™
on
I'm looking for a script that will monitor a directory and move any file that has been sitting in that directory for more than 15 seconds into another directory. Shell script or perl are welcome.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2014
Top Expert 2015
Commented:
perl -e 'while( sleep 1 ){ $^T=time; rename $_,"/another/directory/$_" or warn "$_ $!" for grep -f && -M > 15/(60*60*24), <*> }'
Top Expert 2005

Commented:
ozo: You aware that 'sleep 1' in fact may fail to sleep 1 second? In such case it returns 0 :(
while(1) { sleep 1; ... # is somehow safer... Or
while(sleep 1,1) {...

Author

Commented:
thanks it works well.