File Copy based on file receive date

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Copy based on file receive date
# 1  
Old 11-27-2014
File Copy based on file receive date

I have bunch of files in my source folder like below and every day based on date I am receiving file ex: Nov 28,Nov 29,Nov 30 ...

-rw-rw-r--+ 1 root  root 20 Nov 27 06:00 aaaa27.txt
-rw-rw-r--+ 1 root  root 20 Nov 28 06:00 aaaa28.txt
-rw-rw-r--+ 1 root  root 20 Nov 29 06:00 aaaa29.txt

  1. I want to copy all files into another destination folder.
  2. Copy should happen based on date like Nov 28,Nov 29..and so on.
  3. Script will not copy the old file dated.
  4. Script will copy only the new file which i receive everyday.

Thanks in advance

Last edited by rbatte1; 11-27-2014 at 10:17 AM.. Reason: Converted to use LIST=1 formatting tags
# 2  
Old 11-27-2014
And where are you having an issue?
What have you done so far?
# 3  
Old 11-27-2014
Already i am trying to achieve this by below script

# Go to the directory from where want to copy files

cd /mydir
find . -type f -mtime 1 -exec cp {} /destdir\;
find . -type f -mtime 1 -exec cp {} /destdir1\;

And then installing this script in crontab as @daily so it can be run everyday 12 am.

Is there any other way to achieve?
# 4  
Old 11-27-2014
The find -mtime 1 primary looks for files that are exactly 24 hours old. If you run two invocations of find a second apart, they will not copy the same file (if either of them finds any file at all).

If your script runs close to midnight every night and your daily file comes in around 6am every morning, you can get by with:
cd /mydir
find . -type f -mtime -1 -exec cp {} /destdir\;
find . -type f -mtime -1 -exec cp {} /destdir1\;

to copy files that are less than 24 hours old.

If you might get a file close to midnight (just before, while, or just after your script is run) or your cron job might not run every day (and you still want to copy each file exactly once), you could try something like:
cd /mydir
touch /destdir/.now
find . -type f -newer /destdir/.previous -exec cp {} /destdir \;
find . -type f -newer /destdir/.previous -exec cp {} /destdir1 \;
mv /destdir/.now /destdir/.previous

You'll need to create /destdir/.previous with an appropriate timestamp before you run this script the first time, but after that it should do what you want. There is, however, a chance that a file will be copied twice (once today and once again tomorrow) if a file is created in /mydir while your script is running.
# 5  
Old 11-27-2014
Thanks Don Cragun for your reply..

Surly I will do that and monitor. Any issue i face let you know...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find and copy .zip file based on today's date

Hi Team, I'm new to unix and i have a requirement to copy or move files from one directory to another based on current date mentioned in the .zip file name. Note that i need to copy only the recent zip file. please help me with the code i tried the code as: #! /usr/bin/sh find... (3 Replies)
Discussion started by: midhun3108
3 Replies

2. Shell Programming and Scripting

Bash to copy file 3 times and rename based on another file

In the below bash I am trying to copy the only text file (always only one) in /home/cmccabe/Desktop/list/QC/metrics.txt and rename each of the 3 text files according to /home/cmccabe/Desktop/test/list.txt using lines 3, 4 ,5. This format (that is list.txt) is always 5 lines. Thank you :). ... (12 Replies)
Discussion started by: cmccabe
12 Replies

3. HP-UX

HP/UX command to pull file name/date based on date

HI, Can anyone tell me how to pull the date and file name separated by a space using the find command or any other command. I want to look through several directories and based on a date timeframe (find -mtime -7), output the file name (without the path) and the date(in format mmddyyyy) to a... (2 Replies)
Discussion started by: lnemitz
2 Replies

4. Shell Programming and Scripting

Script to determine Date,TotalFile,total size of file based on date

I have file listed like below -rw-r--r--+ 1 test test 17M Nov 26 14:43 test1.gz -rw-r--r--+ 1 test test 0 Nov 26 14:44 test2.gz -rw-r--r--+ 1 test test 0 Nov 27 10:41 test3.gz -rw-r--r--+ 1 test test 244K Nov 27 10:41 test4.gz -rw-r--r--+ 1 test test 17M Nov 27 10:41 test5.gz I... (5 Replies)
Discussion started by: krish2014
5 Replies

5. UNIX for Dummies Questions & Answers

Copy log based on from-date and to-date

Hi all, i go a customer support requirement where i need to scan several files based on from/to date like 1-oct to 2-oct please help... (3 Replies)
Discussion started by: AbhiJ
3 Replies

6. Shell Programming and Scripting

copy range of lines in a file based on keywords from another file

Hi Guys, I have the following problem. I have original file (org.txt) that looks like this module v_1(.....) //arbitrary number of text lines endmodule module v_2(....) //arbitrary number of text lines endmodule module v_3(...) //arbitrary number of text lines endmodule module... (6 Replies)
Discussion started by: kaaliakahn
6 Replies

7. UNIX for Dummies Questions & Answers

Copy a file based on the size-Urgent

Hi, I need unix code to check the size of a file. for example if the size of the file in A folder is more than 1BM, then i have to move that particular file in to B folder whenever I run that particular script. regards, Srinivas. (7 Replies)
Discussion started by: vysrinivas
7 Replies

8. Shell Programming and Scripting

Copy input file based on condition

Hi, I am new to unix shell programming. I want to write a shell script for a functionality existing in mainframe system. I have one file as below as input 123456 &__987 &12yuq abcdef _ referes to blank condition:whenever the input file is having &__ ,it should be replaced... (4 Replies)
Discussion started by: charan0703
4 Replies

9. UNIX for Dummies Questions & Answers

Copy a file with name as date??

Hi I want to copy a file but append the date and So copying the file file1.txt will have file1_20061009_0950.txt I know the command : date +"%Y%m%d_%H%M" but how do i get this in the file name ? cp file1.txt newDirectory/file1_?????????.txt Thanx (2 Replies)
Discussion started by: chris_ie
2 Replies

10. Shell Programming and Scripting

How to copy a file according to the date

Hi, I want to copy a some files according to the date. lets say i want to copy file from june1st to june14th. What is the command for that ? Thanks, Nayanajith. (1 Reply)
Discussion started by: Nayanajith
1 Replies
Login or Register to Ask a Question

Featured Tech Videos