Please help in making archive for directories with according to same name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please help in making archive for directories with according to same name
# 1  
Old 12-15-2009
Please help in making archive for directories with according to same name

Hello folks,

i have folder in that directory /var/qmail/Mail2DB/ from 000,001,002,003 onwards to 198. it means i have total 199 directories start from 000 thru 198. i have another directory /misc, i want to compress each folder /var/qmail/Mail2DB/000 and make a tar file like 000.tar, 0001.tar .... 198.tar. in /misc directory. can anyone suggest please. Between i want to use sleep for 10 second after each directory compress because i am using older version of linux so thats why, because after sometime it give me broken pipe error. i am waiting for suggestion please.

Thanks,
Bash
# 2  
Old 12-15-2009
Pseudo-codeish:
Code:
change into /var/qmail/Mail2DB
for each folder here
    tar & compress the folder into a file in /misc
    sleep for 10 seconds

Depending on how much error checking you need/want it's between 5 and n lines of code.
# 3  
Old 12-15-2009
Hi.

What gives you a "broken pipe" error? You didn't show any code.

With no error checking whatsoever...
Code:
cd /var/qmail/Mail2DB
ls -d [0-9][0-9][0-9] | xargs -I{} tar cvf /misc/{}.tar {}
gzip /misc/*.tar

(change all the [][][] stuff to just * if that's all you have there)
# 4  
Old 12-15-2009
Quote:
Originally Posted by scottn
Hi.

What gives you a "broken pipe" error? You didn't show any code.

With no error checking whatsoever...
Code:
cd /var/qmail/Mail2DB
ls -d [0-9][0-9][0-9] | xargs -I{} tar cvf /misc/{}.tar {}
gzip /misc/*.tar

(change all the [][][] stuff to just * if that's all you have there)

Hello Thanks for your suggestion, but i need to ignore 009 and 028 during this tar, how i can do that and i also want to give sleep of 10 second after every tar. is it possible i can start from 011 to 199, because this range thing will also resolve my issue alot.
# 5  
Old 12-15-2009
That's funny because when you counted from 000 to 198 and concluded that was 199 things, I was agreeing with you! I just never thought to remove two random directories Smilie

I've never known UNIX (or Linux) to get bored doing stuff and deciding to pull the plug on a pipe, but OK, but I'm not that old.

New plan:

Code:
cd /var/qmail/Mail2DB

cat << ! > dont_tar_me.txt # modify as required
009
028
!

ls -d [0-9][0-9][0-9] | grep -vf dont_tar_me.txt | while read LINE; do
  tar cf - "$LINE" | gzip > /misc/"$LINE".tar.gz
  sleep 10
done

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Solaris

Giving read write permission to user for specific directories and sub directories.

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. This is for Solaris. Please help. (1 Reply)
Discussion started by: blinkingdan
1 Replies

2. 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

3. UNIX for Dummies Questions & Answers

List the directories, having given pattern in the directories name, sorted by creation date

It is for HP-Unix B.11.31. Requirement: 1. List the directories, having given pattern in the directories name, sorted by creation date. Example: Directories with name "pkg32*" or "pkg33*" 2. On the output of 1. list the directories by creation date as sort order, with creation date... (2 Replies)
Discussion started by: Siva SQL
2 Replies

4. Shell Programming and Scripting

How to list all the directories, sub directories in a mount along with size in ascending order?

Hi , I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In a particular mount, have to list all the directories and sub directories along with size of the directory and sub directory in ascending order. Please help me in this regard and many... (4 Replies)
Discussion started by: nmakkena
4 Replies

5. Shell Programming and Scripting

Extracting from archive | compressing to new archive

Hi there, I have one huge archive (it's a system image). I need sometime to create smaller archives with only one or two file from my big archive. So I'm looking for a command that extracts files from an archive and pipe them to another one. I tried the following : tar -xzOf oldarchive.tgz... (5 Replies)
Discussion started by: chebarbudo
5 Replies

6. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

7. AIX

recursive archive directories and subdirectories

Hi everyone, Maybe this is simple question for many of you, but I get confused.:confused: How to archive a parent directory which contains some subdirectories and some files? I have searched this forum, there are some commands like tar,etc, I tried but can not be implemented in my system.... (6 Replies)
Discussion started by: wilsonSurya
6 Replies

8. Shell Programming and Scripting

making a archive script

Hi All: I'm not much of a script writer so I could use your input. Here's the objective... Need a script that will archive (tar) files based on date and then move them into an archive directory. The file names are as follows... S20070101.001 Year month day S20070102.001 As you can see... (1 Reply)
Discussion started by: jimmyc
1 Replies
Login or Register to Ask a Question