Aug
01
2017




BASH script to cp/mv files of a certain date

I have a client that owns a high volume call center.  For quality assurance and training purposes they record all the calls.  Periodically the volume of recorded calls grows to the point that it slows down the NFS share to the Queuematrics call center software(Tomcat app).  I wrote a script that finds files by time and moves them to a different directory.

Usage: copy-by-date.sh -i INPUT_PATH -o OUTPUT_PATH -d +DAYS_OLD

I created two test folders for INPUT(“files”) and OUTPUT(“My drive”).

[matt@mattcom1 copy-by-date]$ ls
copy-by-date.sh files My drive README
[matt@mattcom1 copy-by-date]$

I the “files” folder I have four test files.  I modified the time stamp so three of them appear to be from 2016.

[matt@mattcom1 copy-by-date]$ ls -al files
total 8
drwxrwxr-x 2 matt matt 4096 Aug 1 03:24 .
drwxrwxr-x 5 matt matt 4096 Aug 1 03:24 ..
-rw-rw-r– 1 matt matt 0 Jan 18 2016 test1.wav
-rw-rw-r– 1 matt matt 0 Jan 18 2016 test2.wav
-rw-rw-r– 1 matt matt 0 Jan 18 2016 test3.mp3
-rw-rw-r– 1 matt matt 0 Jul 31 23:32 test4.wav
[matt@mattcom1 copy-by-date]$

 

[matt@mattcom1 copy-by-date]$ ./copy-by-date.sh -i files -o ‘My drive’ -d +100
Copying: files/test1.wav to My drive
Copying: files/test2.wav to My drive
Copying: files/test3.mp3 to My drive

The above script moved all files is input directory to the output directory. 

[matt@mattcom1 copy-by-date]$ ls My\ drive/
test1.wav test2.wav test3.mp3

The script still needs more testing and I’m adding an option to “–copy-only” using ‘cp -rfp’ rather than ‘mv’.  Check back for an update when I get back from vacation.  Thank you for reading.

 

 

If you like this article tell Google!!









Written by mattb in: Linux,Scripts | Tags: , , , ,

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment