Link to home
Create AccountLog in
Avatar of m_travis
m_travisFlag for United States of America

asked on

Linux Scripting

I have a folder full of .tar files that all need to be opened. Then in each tar file there is a log folder, then ids folder, then another folder(name could be proventia_g400, proventia_a201, or proventia_gx5008c), Then folders labeled by years, in each of those are folders labeled by month and in each on of them are folders labeled by day and in there are .gz files that need to be unzipped. I am looking to write a script to do this. I have never created a script in linux before so this is a learning experience for me also. I have supplied a graphical representation of the folder layout, to help everyone better understand the file structure.
Drawing3.jpg
SOLUTION
Avatar of Steven Vona
Steven Vona
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of xRalf
xRalf

Hello,

what about

tar -xvf *; for i in `find . -name '*.gz'`; do gunzip "$i"; done
Avatar of m_travis

ASKER

okay, so I open up a texteditor and paste the code in and save the file as what?
1) Put All the tar files in a specific directory, say mytarfiles

2)
#Untar all the tar files and create a subdirectory structure
tar -xvf *.tar

3)

The shell script to do the untar operation.
Save this shell script in a file , say magic.ksh
and execute it
To execute a shell script
./magic.ksh

#Get the list of untared directories

for i in $(ls)
do
   cd $i/Logs/Ids/
   for j in Proventia_g400 Proventia_a201 Proventia_gx5208c
   do
       find . -name *.gz -exec gunzip '{}' \; #Unzip each file in respective directories.
   done

done

#*Note that Unix is case sensitvie hence correct the case of folder/file names if this script does not work
I type "sudo tar -xvf *.tar" and get back the error "tar: (filename).tar: Not found in archive" but when i type ls, the file is in the directory
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
after i type "tar -xvi < *.tar"
Returns "bash: *.tar: ambiguous redirect"
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account