473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Moving Files Based on Date

How can I move files based on date specifically for the case below:

1. crontab runs every hour
2. any file in directory 1 dated less than the current hour is moved to directory 2.
eg file1 time stamp 2:59
file2 time stamp 2:45
file3 time stamp 2:05
file4 time stamp 3:08
3. crontab runs at 3:15, so file1,2,3 are moved to directory2
Jun 22 '07 #1
2 4288
tifoso
41
Have the cron job call a perl script is quicker/cleaner get stat of each file on the folder(s) and compare the dates to current system time and move it properly

Ciao
Jun 22 '07 #2
prn
254 Expert 100+
tifoso is right. This is much easier done in Perl than in a shell script. Here's an example:
Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/perl
  2. use strict;
  3. my $destination_directory = '/foo/d2';
  4. foreach my $file (glob "*") {
  5.     my $mtime = (stat("$file"))[9];
  6.     my $now = time();
  7.     my $diff = $now - $mtime;
  8.     print "age of $file is $diff \n";
  9.     # running at x:15 -- 15 minutes = 900 seconds
  10.     if ( $diff > 900 ) {
  11.         print "should move $file to $destination_directory/$file\n";
  12.         #rename $file $destination_directory/$file;
  13.     }
  14. }
  15.  
You would, of course, want to change the value of $destination_directory to whatever is appropriate, uncomment the "rename" line and, of course, you can delete the print statements that just show you what is going on.

Best Regards,
Paul
Jun 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Stephen Miller | last post by:
Firstly, sorry for the long post, but I've included a fair bit of sample data. Im doing a comparision of 10yr Bond prices and CPI adjustments, with an 18 week moving average of the CPI. I'm...
5
by: Franck | last post by:
Hello, I've just moved to visual developper 2005 to do so, I also had to use the convert assistant. what it did; moving my file resx files that i had in a diresctory called resx to a new...
3
by: c0l0nelFlagg | last post by:
I have a moving dispatcher database. There are 99 drivers, 99 loaders, and 50 different vehicles. The scheduler database is built on a 13 4 week month year so that it can be used repeatedly in any...
2
by: David Thielen | last post by:
So we have moved our app from .NET version 2.X in IIS6 to a Windows 2008 Server running IIS7. We have copied all files to the Windwardreports\apps directory and that apps directory has been...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.