Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Archive Script 1

Status
Not open for further replies.

bide

IS-IT--Management
Jul 6, 2001
2
US
I need help with a script that will back up files to a new directory. I need to select the files by date range, but the files are named with doc followed by a random number. I want a new directory for files every day so I can look at them by day if I need to. For example I want a directory called Jun19 that contains all of the document files from June 19. And if there is a way to compress the files that would be nice but it is not totally neccessary.
 
Here is a script I wrote which does something much like what you have asked. You might have to change a few things to get the results you want but this will do it.

The script copies files from one directory into a directory for each month. It checks for a year directory, if no year directory is found one is created then it creates a new directory for each month and copies the files over. The key to the script you need is using the cut command along with the date so you grab the correct information. Give it a try and tell me how it works out :)

Hope this helps,

Tcorum

Script follows:

#!/usr/bin/ksh

m1=$(date |cut -c 5-8)
y1=$(date |cut -c 25-28)

if [ ! -d $y1 ]
then
mkdir $y1
fi

if [ ! -d $y1/$m1 ]
then
mkdir $y1/$m1
fi
#mkdir $y1 >null
#mkdir $y1/$m1 >null
cp -f *.pdf $y1/$m1

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top