I am using the below commands (in a single line) in my script to tar the files as per your suggestion.
PHP Code:
FILE_LIST=`ls $ENVID_*_$DATE_OF_RUN.$ENVID_*.TXT` | echo "files are $FILE_LIST" >>${logfile} | tar -zcf ${ENVID}_$(date +"%Y%m%d%H%M%S").tar.gz /opt/informatica/infa_shared/SrcFiles/arch
I see a *.tar.gz in the path I am running the script. But I thought the tar file to be in /opt/informatica/infa_shared/SrcFiles/arch path. can you please advice?
Also, I would like to unzip/untar back the files to verify if the files are tar-red properly.. and used the below command from command line. It actually returns me the path - /opt/informatica/infa_shared/SrcFiles/arch but there are no files extracted... I am expecting to see the files individually.. can you help on how to extract the files?
PHP Code:
$ tar -zxvf FERAL_20120201100113.tar.gz opt/informatica/infa_shared/SrcFiles/arch/
tar works the way I showed you, not the way you're trying to use it.
Since you refuse to explain any of the details, I still have no idea what you're even trying to do. I also asked what your system was and received no answer. This information is needed to answer some of your questions.
Why would the tar file be in /opt/informatica/infa_shared/SrcFiles/arch when you told tar to read files from /opt/informatica/infa_shared/SrcFiles/arch ? It ends up in the current directory because you didn't tell it anything else.
There is also much useless use of ls * in your code. ls is not the thing that understands *, any command is given the corresponding filenames when you use *. You might as well just put the * where you want the filenames to appear in the first place -- which is, as I demonstrated, the last arguments of tar.
You also have lots of unbracketed variables which are going to screw up. _$DATE_OF_RUN_$OTHER will mess up because you have no variable named $DATE_OF_RUN_. You use ${VARNAME} style brackets to defeat that.
I'll venture a third try at what I'm guessing you want:
And again, if you tell me what your system is, there may or may not be a 'verify' option that would be of use to you. But there's no point pointing it out if you don't have it. What is your system?
My requirement is to take some files from landing directory (there will be many files, but I need to pick the files based on the date - the date value is stored in another file) and then archive them to another directory. As I have to pick only certain files, I used ls command to get a list of them.
This is just to back up the files and if the need be, the tar files from the archive directory has to be used and the individual files (like how it was initially) are taken from it and to be sent to landing directory for processing the files.
As it would occupy less space by ZIP ing them, I was trying to zip the files separately and store all the files to a single tar file.
I was told to zip them all individually and tar the zip-ped files into a single tar file. But, I remember that you said it is done the other way round. I am fine with it as long as I can untar and unzip the files and bring them back as individual files (like how it was)...
Thank you. You can use your version of tar to verify while it's creating the tarball, then, by doing tar --verify ....
Quote:
As it would occupy less space by ZIP ing them, I was trying to zip the files separately and store all the files to a single tar file.
The usual procedure is the opposite -- compress the tar. This also does a better job of preserving the file's permissions, something pure tar is very good at; if you went and mangled all the files by zipping them first, how well that'd work is anyone's guess.
Quote:
I was told to zip them all individually and tar the zip-ped files into a single tar file. But, I remember that you said it is done the other way round. I am fine with it as long as I can untar and unzip the files and bring them back as individual files (like how it was).
Doing it the other way around means you can extract them directly, and not have to unzip them individually. And you get good compression either way, especially with text files.
With TAR verify, will I be able to extract the files back from the .tar.gz file?
eg., I create a .tar.gz file on all the below files. After I execute my script, I see that the .tar.gz file is created. Now, I want to execute some commands and see that I am able to extract all the below files individually, like how they are below. I want to untar / unzip to get the individual files, do you know if this is achievable?
PHP Code:
-rw-r--r-- 1 z06189 bi 16061 Jan 30 16:33 FERAL_CONTROL_20120115.FERAL_CTRL.txt -rw-r--r-- 1 z06189 bi 0 Jan 31 11:46 FERAL_CONTROL_20120131.FERAL_CNTRL.TXT -rw-r--r-- 1 z06189 bi 135 Jan 31 13:14 FERAL_CONTROL_20121213.FERAL_CTRL.TXT -rw-r--r-- 1 z06189 bi 194 Jan 31 11:53 FERAL_DATA1_20120131.FERAL_DATA.TXT -rw-r--r-- 1 z06189 bi 102 Jan 31 13:20 FERAL_DATA1_20121213.FERAL_98312.TXT -rw-r--r-- 1 z06189 bi 91 Jan 31 11:53 FERAL_DATA_20120131.FERAL_CNTRL.TXT
also, I used the TAR verify on the command prompt, but was not successful.
below are the commands... can you help?
PHP Code:
sh-3.2$ tar -xW verify FERAL_20120201125930.tar.gz tar: Cannot verify stdin/stdout archive tar: Error is not recoverable: exiting now sh-3.2$ tar -tW verify FERAL_20120201125930.tar.gz tar: Cannot verify stdin/stdout archive tar: Error is not recoverable: exiting now sh-3.2$ tar -cW verify FERAL_20120201125930.tar.gz tar: Cannot verify stdin/stdout archive tar: Error is not recoverable: exiting now
With TAR verify, will I be able to extract the files back from the .tar.gz file?
You extract the files with tar -C /path/to/destination/folder/ -zxf filename.tar.gz
Quote:
also, I used the TAR verify on the command prompt, but was not successful.
You really need to read more carefully.
1) It's not verify, it's --verify.
2) You use it when creating the archive. It's not an extra step. Just add --verify in front when creating the archive.
Also, since the files are .tar.gz hence already compressed, you need the -z flag.
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)