script to archive certain folders in a hierarchy


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to archive certain folders in a hierarchy
# 1  
Old 04-28-2005
Tools script to archive certain folders in a hierarchy

I'm new to shell scripting and I'm having a tough time figuring out how to script something. Can anyone help?

Here is my setup and what I want to do:

A directory contains a list of projects by year (2000, 2001, etc) and customers (01-001) all of which have the same internal directory setup (1-Current Drawings, 2-Quotes etc...) So like this:

/Server/Projects/2000/001-001/
/Server/Projects/2000/001-002/
etc..
/Server/Projects/2001/005-0045/
/Server/Projects/2001/005-0045/
etc...

Remember EACH of these directories have the same internal folder structure like

1-Current Drawings
2-Quotes
3-Invoices
4-Archived Drawings
etc...

What I want to do is ZIP or TAR the 1-Current Drawings directory (leave the files loose however), move the created archive into the 4-Archived Drawings directory and time stamp the archive name and do this for EACH directory in Projects directory.

So basically some sort of loop to enumerate the Projects in each year and customer, find the 1-Current Drawings, archive it, move it into the appropriate folder of each customer, timestamp the archive, move on to the next customer and year.

In my mind this should be easy but shell scripting is not my forte.

If someone can give a short example that works on a given structure I can probably handle the rest and customize it to my liking. Thanks!
# 2  
Old 04-28-2005
shell script..

Hi,

This should do the job :


#!/bin/sh
WD=/home/slava/forum

TODAY=`date +%d%m%y`

cd "$WD"
for YEAR in `ls -d 2???`
do

cd "$WD/$YEAR"
for PROJECT in `ls -d ???-?*`
do

if [ -d "$WD/$YEAR/$PROJECT/1-Current Drawings" ]
then

cd "$WD/$YEAR/$PROJECT"
tar cfv \
"1-Current Drawings.$TODAY.tar" \
"1-Current Drawings" >/dev/null
mkdir -p "$WD/$YEAR/$PROJECT/4-Archived Drawings"
mv "1-Current Drawings.$TODAY.tar" \
"$WD/$YEAR/$PROJECT/4-Archived Drawings/"
fi
done
done

Slava R.
# 3  
Old 04-28-2005
OK great, so far so good however one little problem..

On an OS X system, some directories with spaces in the name can be escaped as such:

05-028\ West\ Oak\ Trails

On an ls -d ??-* file listing everything is ok but the script kaks where it detects the projects listing. It's balking at the spaces in the name.

sh -x ./script reports that part as such:

+ '[' -d /Volumes/230GB/SDG/1-Projects/2005/05-067/ ']'
+ '[' -d /Volumes/230GB/SDG/1-Projects/2005/Laffey/ ']'
+ '[' -d /Volumes/230GB/SDG/1-Projects/2005/House/ ']'

That directory is supposed to be 05-067 Laffey House

Is there a way to prevent the script from munging the directory name and keeping it all on 1 line??

One I fix this I'm good to go! Greta script, I learned a lot from it.
# 4  
Old 04-28-2005
change:
for PROJECT in `ls -d ???-?*`

TO
for PROJECT in "`ls -d ???-?*`"
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to archive logs and sftp to another archive server

Requirement: Under fuse application we have placeholders called containers; Every container has their logs under: <container1>/data/log/fuse.log <container1>/data/log/fuse.log.1 <container1>/data/log/fuse.log.XX <container2>/data/log/fuse.log... (6 Replies)
Discussion started by: Arjun Goswami
6 Replies

2. UNIX for Beginners Questions & Answers

Building hierarchy with the list

Hi All, Sorry for more question today. I am having a text file . Like below 704925680_TOTAL->MANUAL->TT IOR GSB 775116444_TOTAL->POO TO->TT -572275295_TOTAL->MANUAL->MTO -611408278_TOTAL->PRIE LEL 456690129_TOTAL->BTT TOO 475919266_TOTAL->MANUAL->COM -172680236_TOTAL->BTT TOO->MTO... (15 Replies)
Discussion started by: arunkumar_mca
15 Replies

3. Shell Programming and Scripting

Shell script to call Oracle archive backup script when file system reaches threshold value

Hello All, I need immediate help in creating shell script to call archivebkup.ksh script when archive file system capacity reaches threshold value or 60% Need to identify the unique file system that reaches threshold value. ex: capacity ... (4 Replies)
Discussion started by: sasikanthdba
4 Replies

4. UNIX for Dummies Questions & Answers

Archive folders and sub folders

Hi Can i archive folder and folders in with the tar command My files are located in subfolders Eg: Folder1/Folder1_1/*.pdf Folder1/Folder1_2/*.pdf Folder1/Folder1_3/*.pdf so i would like to tar all the files in Folder1_1 and Folder1_2 only not Folder1_3 that should be done next... (2 Replies)
Discussion started by: cnrj
2 Replies

5. Shell Programming and Scripting

Archive files to different target folders based on criteria

Hi All, I am creting archive script in which i need to split the source file's to different target folder's based on the input file name first character. Input1.txt -- will contains file names that are needs to be Archive. Input1.txt A1213355 B2255666 C2254555 A6655444 C5566445 ... (2 Replies)
Discussion started by: kmsekhar
2 Replies

6. Shell Programming and Scripting

Archive different folders based on their names

This is my first post so ... be gentle:) Hello I have several folders that are backed up daily in following format: /back_YY.MM.DD/backup1/* ........................./backup2/* I looking a script to archive and rename all backup folders bazed on root folder... (8 Replies)
Discussion started by: vilibit
8 Replies

7. UNIX for Dummies Questions & Answers

How to Archive Folders in T-Shell

Hi i am new to Unix Shell Programming... i m just a beginner and i m training myself in Unix.... I need a sample code to archive folders in my Windows OS using Unix commands... Can someone Help me? (1 Reply)
Discussion started by: aegan
1 Replies

8. Shell Programming and Scripting

Script calling hierarchy

If a.sh calls b.sh, how can we know inside b.sh that it was called by a.sh? (4 Replies)
Discussion started by: chaitu_inmage
4 Replies

9. Solaris

Why are so many dirs used in solaris hierarchy?

Hi all, I would like to know the difference between the different dir structures present in solaris!!! Meaning what does /usr contain, /etc ,/opt/ ,so on... I know what /usr and /etc are used for. But why are /opt /bin /sbin /var and many more that i have missed I would appreciate if... (1 Reply)
Discussion started by: wrapster
1 Replies
Login or Register to Ask a Question