Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems using bzip2 to compress a tar 1

Status
Not open for further replies.

warburp

IS-IT--Management
Oct 27, 2003
44
GB
Hi

I'm trying to compress a tar archive within a script to dsave space but I have run into problems. I can't seem to get it to work even from the command line.

The file I have is approx 5GB and I am using bzip 0.9.0c that was shipped with Solaris 8 2/02. I can seem to compress other files even of a similar size, but when I try to compress the tar I get a message 'bzip2: Input file hottest18112004110457.tar doesn't exist, skipping.'. I have tried making the file name shorter without any sucess. The command I am running is as follows:

/usr/bin/tar -cvf <target_file>.tar <source> | /usr/bin/bzip2 <target_file>.tar

Anyone any idea, is this the correct syntax?

Thanks

Phil.
 
What about this ?
/usr/bin/tar -cvf <target_file>.tar <source>; /usr/bin/bzip2 <target_file>.tar


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
You wrote:
Code:
/usr/bin/tar -cvf <target_file>.tar <source> | /usr/bin/bzip2 <target_file>.tar

[tt]tar -cvf target.tar target[/tt] says, "Create [tt]target.tar[/tt] containing [tt]target[/tt]; put the archived files onto standard output (or maybe it's standard error...)"

[tt]bzip2 target.tar[/tt] says, "Take [tt]target.tar[/tt] and zip it up as [tt]target.tar.bz2[/tt]; don't read anything from standard input."

The [tt]|[/tt] symbol between the two commands says, "Take the standard output of the first command and pipe it into the standard input of the second command." Since, as mentioned before, the first process isn't putting anything useful into standard output and the second process isn't reading anything from its standard input anyway, that's a bit of a nonsensical thing to do.

Also, as a side effect, the [tt]|[/tt] causes both commands to start at mostly the same time and run "alongside" each other. Since the [tt]tar[/tt] process will most likely not have finished creating the archive at the time the [tt]bzip2[/tt] process starts, you're telling bzip2 to process a file that does not exist at the time.

PHV's command replaces the [tt]|[/tt] with a [tt];[/tt], which says, "Wait before the first command finishes before starting the second one." That ensures that the archive exists before you try to zip it. It also doesn't try to use standard input and output.


When you wrote you command, you were probably thinking of something more like this:
Code:
tar c target | bzip > target.tar.bz2

That says, "(tar) Create an archive of target, and put it onto standard output," and "(bzip2) Read a file from standard input and compress it to standard output." And in this case, standard output is being redirected into the file [tt]target.tar.bz2[/tt].


Many modern [tt]tar[/tt] tar programs will have an option specifically for using [tt]bzip2[/tt], however, so you can probably simplify your command. For example, my [tt]tar[/tt] program uses [tt]j[/tt] to indicate that the file should be processed with [tt]bzip2[/tt]. Thus, i would just write:
Code:
tar cjf target.tar.bz2 target

Look at your [tt]tar[/tt] man page to see if such an option exists for you.
 
ChipperMDW

Thanks for the advice, I now understand. Checking my packages I need to update tar to take advantage of this feature. One question, any idea how I remove the current version of tar (loaded as part of Solaris 8) as I cannot see it in the pkginfo. I have tried installing the new version using pkgadd but it still uses the previous version, any tips?

Thanks

Phil.
 
You can probably rename the old /usr/bin/tar, then create a symlink (ln -s <path to new tar> tar) in /usr/bin/

HTH.
 
Can you use the Solaris method to "remove package" on the old tar package, then install the new one? Of course if Solaris packages happen to be tar files, that might not be such a good idea...

Try a [tt]locate tar[/tt] to see if you can find where all the tar programs are installed on your system. Then maybe someone can give you some information based on that.


By the way, you probably figured out what I meant, but just to clarify: my clause, "put the archived files onto standard output" would have been better worded as, "put the names of the archived files onto standard output.
 
I didn't suggest removing the Solaris tar entirely because you never know if or when you might need it. Renaming it leaves it in place to be reverted to if required without the fuss of reinstalling.
 
Right. I didn't mean remove the Solaris tar entirely and not replace it; I meant remove version 1.0 of Solaris's tar and replace it with version 2.0 of Solaris's tar, for example.
 
Thanks to you both. I installed the package and replaced the link for tar to the new location. I left the old package in place as trying to remove it seemed too much like hard work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top