TAR and ZIP files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers TAR and ZIP files
# 15  
Old 02-01-2012
Hi Corona,

thanks for all your inputs, my script tars a file and I am able to extract individual files. the environment file was set up today and I need to use it, for which I changed my script and then I came to know about 2 issues in the script:

1. The script looks for files in the sub directories of the folder where as subdirectory level search is not required.
2. I am looking only for files with certain pattern. below are the file names. but the script does like a wildcard match (if a file name has the $date value in some sub directory, it picks it and tars it), it does not match the complete file name..even if a part of the file name is available, (like .TXT or $ENVID) it picks it and tars it...

PHP Code:
$ENVID_DATA_*_$DATE.$ENVID_DAT.TXT 
$ENVID_CONTROL_
*_$DATE.$ENVID_CTRL.TXT 
$ENVID_TRIGGER_$ENVID
.$ENVID.TRG.TXT  - ( the script I posted here is yet to accomodate this file
code:

HTML Code:
$ cat archival.sh
#### Script to archieve source file and tar them
#!/bin/sh
. /opt/informatica/infa_shared/SCRIPTS/env_file.ksh
date_str=`date "+%Y%m%d%H%M%S"`
ENVID=$1
logfile=$LOGS/${ENVID}_archival_${date_str}.log
echo Script $0 started at `date` >${logfile}
#### Check if one parameter is received#######
if [ $# -ne 1 ]; then
echo "input parameter for the script is missing" >>${logfile} 2>&1
exit 1
fi
##### Get the ENVID and DATE_OF_RUN from the parameter file####
parmfilename=$PARM_FILES/${ENVID}_parm.parm
echo $parmfilename >>${logfile}
DATE_OF_RUN=`cat $parmfilename | grep "DATE_OF_RUN" | cut -d"=" -f2`
echo $DATE_OF_RUN >>${logfile}
#### List files based on input parameter####
TARFILE=$ARCHIVE/${ENVID}_${DATE_OF_RUN}_$(date +"%Y%m%d%H%M%S").tar.gz
# Create the compressed tar file
#tar -zcf "${TARFILE}" ${ENVID}_*_${DATE_OF_RUN}.${ENVID}_*.TXT $SOURCE_FOLDER
tar -zcf "${TARFILE}" ${ENVID}_DATA_${DATE_OF_RUN}.${ENVID}_DAT.TXT  ${ENVID}_CONTROL_${DATE_OF_RUN}.${ENVID}_CTRL.TXT $SOURCE_FOLDER
# List files inside the tar file
tar -ztf "${TARFILE}" >>${logfile}
can you please help me..
# 16  
Old 02-02-2012
* does not match things in subdirectories unless you tell it to, and I wasn't.

You're getting things you didn't want because you're telling tar to archive $SOURCE_FOLDER. If you don't want it to archive $SOURCE_FOLDER, don't give it $SOURCE_FOLDER.

Try the actual command I gave in the first place without adding any extra parameters to it. Throwing on extra parameters just because you feel you want to isn't a good idea -- the computer will take you literally and do it. Only do so if you actually need them...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

2. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

3. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

4. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

5. Shell Programming and Scripting

help with tar & zip only last months(say,Sep) files

Need to 1. archive all the files in a directory from the previous month into a tar/gz file, ignoring all already archived 'tar.gz' files 2. Check created .tar.gz file isnt corrupted and has all the required files in it. and then remove the original files. I am using a function to get the... (1 Reply)
Discussion started by: Prev
1 Replies

6. UNIX for Advanced & Expert Users

How to zip/tar millions of files?

Hi guys, I have an issue processing a large amount of files. I have around 5 million files (some of them are actually directories) in a server. I am unable to find out the exact number of files since it's taking "forever" to finish (See this thread for more on the issue). Anyway, now I... (6 Replies)
Discussion started by: verdepollo
6 Replies

7. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

8. Shell Programming and Scripting

To write a shell script which groups files with certain pattern, create a tar and zip

Hi Guru's, I have to write a shell script which groups file names based upon the certain matching string pattern, then creates the Tar file for that particular group of files and then zips the Tar file created for the respective group of files. For example, In the given directory these files... (3 Replies)
Discussion started by: rahu_sg
3 Replies

9. UNIX Desktop Questions & Answers

Using Tar Zip

Hi, I want to backup my SQL database using tar zip but I'm paranoid that I will archive it. What I mean is I want the files to stay where they are but make a zipped copy of the files as well, I don't want to delete the originals. Is the command? tar -cvzf databasename.tar.gz... (1 Reply)
Discussion started by: chickenhouse
1 Replies

10. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies
Login or Register to Ask a Question