Sponsored Content
Top Forums Shell Programming and Scripting Uncompress several tar.gz files inside several folders Post 303020014 by shellX on Thursday 12th of July 2018 04:54:01 AM
Old 07-12-2018
Hi Robin

That code is very good.

The issue is it doesn't work when there are more then one tar.gz file in the folder.

--> Lets suposse $1 = folder
--> The content of my folder "folder" is
Code:
[shellx] $ ls -l folder
total 16
drwxr-xr-x 2 shellx mrv 4096 11 juil. 14:36 001
drwxr-xr-x 2 shellx mrv 4096 11 juil. 14:37 002
drwxr-xr-x 2 shellx mrv 4096 11 juil. 14:37 003
drwxr-xr-x 2 shellx mrv 4096 11 juil. 14:34 004

--> sub-folders (001, 002, 003, 004) content
Code:
[shellx] $ ls  folder/*
folder/001:
CARDV022A0.tar.gz  CARDV02976.tar.gz  CARDV02A0.tar.gz  CARDV976.tar.gz

folder/002:
CARDV02976.tar.gz  CARDV976.tar.gz

folder/003:
CARDV022A0.tar.gz  CARDV02976.tar.gz  CARDV976.tar.gz

folder/004:
CARDV02976.tar.gz  CARDV976.tar.gz



-->I've set 2 loops in the new script

Code:
#!/bin/bash
liste_rep="folder/*"
folder="$(ls folder)"
echo "LISTE REP :" $liste_rep
        for rep in "$liste_rep"
        do
                echo "AFFICHE REP :"$rep
                #for fichier in "$(ls /folder/*)" # test
                for fichier in $liste_rep/*.tar.gz
                do
                        #cd $liste_rep
                        echo "FICHIER :" $fichier
                        tar -zxvf $fichier   --directory $liste_rep/
                done
        done
exit


-->Variables content verified
Code:
[presta2] $ echo $liste_rep
folder/001 folder/002 folder/003 folder/004
-(jeu. juil. 12 10:13:41)--(mrvpgsa001:~)-
[presta2] $ echo $folder
001 002 003 004


Resultat d'execution
Code:
LISTE REP : folder/001 folder/002 folder/003 folder/004  --->> folder liste correct
AFFICHE REP :folder/*  --->> because $rep = "$list_rep"??? and should be $list_rep without " " ?
FICHIER : folder/001/CARDV022A0.tar.gz  --> Var fichier is correctly set
tar: folder/002 : non trouvé dans l'archive ---> How is it ? if  --> tar -zxvf $fichier
tar: folder/003 : non trouvé dans l'archive
tar: folder/004 : non trouvé dans l'archive
tar: Arrêt avec code d'échec à cause des erreurs précédentes
FICHIER : folder/001/CARDV02976.tar.gz
tar: folder/002 : non trouvé dans l'archive
tar: folder/003 : non trouvé dans l'archive
tar: folder/004 : non trouvé dans l'archive
tar: Arrêt avec code d'échec à cause des erreurs précédentes
FICHIER : folder/001/CARDV02A0.tar.gz
tar: folder/002 : non trouvé dans l'archive
tar: folder/003 : non trouvé dans l'archive
tar: folder/004 : non trouvé dans l'archive
tar: Arrêt avec code d'échec à cause des erreurs précédentes
FICHIER : folder/001/CARDV976.tar.gz

--> If uncomment line "#cd $liste_rep" inside second loop
--> we gett error message below

Code:
[presta2] $ ./decomp2.sh
LISTE REP : folder/001 folder/002 folder/003 folder/004
AFFICHE REP :folder/*
FICHIER : folder/001/CARDV022A0.tar.gz
tar (child): folder/001/CARDV022A0.tar.gz : la fonction open a échoué: Aucun fichier ou dossier de ce type
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
FICHIER : folder/001/CARDV02976.tar.gz
tar (child): folder/001/CARDV02976.tar.gz : la fonction open a échoué: Aucun fichier ou dossier de ce type
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now


Any ideas are welcome




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 07-12-2018 at 12:59 PM.. Reason: Added CODE tags.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

uncompress files

I get a compressed file for linux and I want to uncompress it in Unix. Is that possible? I try with te command uncompress but it didn´t work. T.hanks (3 Replies)
Discussion started by: diegoe
3 Replies

2. Shell Programming and Scripting

rsh and uncompress and tar

Hello, how can I send a compressed file (file.tar.Z) on another server ans uncompresse and extract it there ? My code which is like this uncompress *tar.Z | rsh serveurB -l user1 "cd /d15/store/; tar xf -" does not function. Many thanks before. (4 Replies)
Discussion started by: big123456
4 Replies

3. UNIX Desktop Questions & Answers

file zip,rar,tar,compress,uncompress,unzip,unrar

i want know how to compress and uncompress file using unix, compress uncompress,zip,unzip,rar,unrar,how its work and more about this.:confused: (1 Reply)
Discussion started by: ismael xavier
1 Replies

4. Solaris

Cannot uncompress the tar.gz

I've downloaded the tomcat from http://archive.apache.org/dist/jakarta/tomcat-5/v5.0.30/bin/ at window 2000 and then ftp to Solaris 5.9 in binary mode. gunzip -c jakarta-tomcat-5.0.30.tar.gz | tar -xvf - tar: directory checksum error if try this one, gzip -d jakarta-tomcat-5.0.30.tar.gz... (2 Replies)
Discussion started by: sbox
2 Replies

5. Shell Programming and Scripting

uncompress tar.gz files

i Have 150 tar.gz files and i need to uncompress and extract all the files from those 150 tar.gz and i will have 150 files on daily basis. could any one help me out with the script to uncompress tar.gz files. (5 Replies)
Discussion started by: gaddamshashank
5 Replies

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

7. Shell Programming and Scripting

How to tar files inside a script?

Hi , I have a file which contains few file names. I need to tar those files but am unable to do inside the script. Any help will be useful. cat /tmp/test aa.txt bb.txt cc.txt I have tried the below code but its not working. for i in `cat /tmp/test';do tar -cvf TEST.tar $i;done (9 Replies)
Discussion started by: rogerben
9 Replies

8. Shell Programming and Scripting

Listing folders that have a file inside them

Hi guys, I'm new to the forums and putting my foot in the door with SED and AWK. I was wondering if someone could help me as I think I'm making this harder than it needs to be... I have a list of folders named as urls, inside these are log files and possibly a 'status' file. I'm trying to get... (6 Replies)
Discussion started by: KakersUK
6 Replies

9. Shell Programming and Scripting

Editing all files inside folders and updating pos 88-94 with continuous numbering.

Here is expected output:- For each file with following file name pattern we need to look at position 1 inside first file matching our search criteria if first letter of the line is 5 then position 88-94 will be 0000001 then look for line immediately after 5 which starts with i.e. position 1 = 8... (6 Replies)
Discussion started by: lancesunny
6 Replies

10. Shell Programming and Scripting

How to delete all the files and folders inside all the directories except some specific directory?

hi, i have a requirement to delete all the files from all the directories except some specific directories like archive and log. for example: there are following directories such as A B C D Archive E Log F which contains some sub directories and files. The requirement is to delete all the... (7 Replies)
Discussion started by: Little
7 Replies
All times are GMT -4. The time now is 07:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy