Need help with tar script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with tar script
# 1  
Old 12-07-2009
Need help with tar script

The following script is supposed to look at a list of files and folders and tar them all up. Ofcourse you have to strip off everything to the left of the file or folder to tar only that object. My problem is that when I do that my script no longer knows how to find the file or folder. Is there a way of saving in a variable the location of the object you want to tar and have it passed to the for loop with each iteration. I'm trying to stay away from nested loops. Thanks in advance for your help.

Code:
#!/bin/bash
for p in `cat /data/results/filelist`
do
i=`echo $p | awk 'BEGIN{FS="/"}{print $NF}'`
cd $p && tar czf ../$i.tar.gz $i
done

filelist below:

/data/results/solid0155/solid0155_20090918_2x35_LMP_FC2
/data/results/RegressionDriver/CaseManager/tests_era2/cases/performance/155_2x35
_FC2_run_outputs_tillSam
/share/reference/genomes/chromFa/hg18_validated.fasta
/data/results/README



---------- Post updated at 10:35 AM ---------- Previous update was at 09:53 AM ----------

tested solution that a poster gave me:

Code:
tar czf tarball.tar.gz --files-from /data/results/fileslist 

 filelist below:

 /data/results/a/file1
 /data/results/a/b/file2
 /data/results/a/b/c/file3
 /data/results/a/b/c/d/file4
 /data/results/a/test1
 /data/results/a/b/test2
 /data/results/a/b/c/test3
 /data/results/a/b/c/d/test4

 You end up with:

 [root@offline01 results]# ls -ld tarball.tar.gz
 -rw-rw-r--  1 root users 273 Dec  7 11:18 tarball.tar.gz


Last edited by pludi; 12-07-2009 at 03:46 PM.. Reason: code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Do I need to extract the entire tar file to confirm the tar folder is fine?

I would like to confirm my file.tar is been tar-ed correctly before I remove them. But I have very limited disc space to untar it. Can I just do the listing instead of actual extract it? Can I say confirm folder integrity if the listing is sucessful without problem? tar tvf file1.tar ... (1 Reply)
Discussion started by: vivien_chu
1 Replies

2. UNIX for Dummies Questions & Answers

Script help - TAR

*****CAN'T CHANGE THE TOPIC NAME******** I'm using "zip" instead Hi. I'm trying to make my script use "zip" and i want it to compress all the files in a directory to individual zip files... but i can't really figure out how. i have googled around. tried some different things... but i can't get... (6 Replies)
Discussion started by: vYN
6 Replies

3. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

4. Shell Programming and Scripting

tar command dont tar to original directory

HI, if I have a tarfile called pmapdata.tar that contains tar -tvf pmapdata.tar -rw-r--r-- 0/0 21 Oct 15 11:00 2009 /var/tmp/pmapdata/pmap4628.txt -rw-r--r-- 0/0 21 Oct 14 20:00 2009 /var/tmp/pmapdata/pmap23752.txt -rw-r--r-- 0/0 1625 Oct 13 20:00 2009... (1 Reply)
Discussion started by: borderblaster
1 Replies

5. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

6. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

7. Shell Programming and Scripting

using tar via su in a script issue !!!

I am trying to implement the below command in my shell script su - $PROCESS -c `tar -tvf $file|tee -a $LOG/$file.log` The idea is to get the tar output on the screen and at the same time it should put the output in the log file. Problem is: 1) I donot get the output on the screen. 2)... (3 Replies)
Discussion started by: kpatel786
3 Replies

8. UNIX for Advanced & Expert Users

Tar utility (untar a .tar file) on VxWorks

Hi All Can someone pls guide me if there any utility to compress file on windows & uncompress on vxworks I tried as - - compressed some folders on windows ... i created .tar ( to maintain directory structure ) and compressed to .gz format. - on VxWorks i have uncompressed it to .tar... (1 Reply)
Discussion started by: uday_01
1 Replies

9. UNIX for Dummies Questions & Answers

tar in a script

I am trying to write a simple script where I tar a few files and send them to tape The code looks like this: tar -cvf archive/tam/*20080507* archive/sam/*20080507* source/delta/*20080507* This runs fine from the command line but when i try to run this in a script I get an end of tape... (3 Replies)
Discussion started by: zapper222
3 Replies

10. Shell Programming and Scripting

how to write script in tar

i have the script.in this script comprees formatlike tar and insert to another directory and another sever.and how to write this process in script . iam new for unix how to do this process. please helpmea naveen.g (1 Reply)
Discussion started by: naveeng.81
1 Replies
Login or Register to Ask a Question