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

Pseudo-codeish:

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.

Hi.

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

With no error checking whatsoever...

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.

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 :wink:

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:

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