LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-06-2012, 04:13 PM   #1
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
tar -W or tar --diff help


both tar -W and --diff are failing each for separate reasons, but still just as annoying.

Code:
[server@user rx30]$ tar -cjvf test.tar.bz2 /www/http/docs/rx30/*.sh
tar: Removing leading `/' from member names
/www/http/docs/rx30/autoftp.sh
/www/http/docs/rx30/autoftpd.sh
/www/http/docs/rx30/back.sh
/www/http/docs/rx30/connect.sh
/www/http/docs/rx30/freespc.sh
/www/http/docs/rx30/modemflash.sh
/www/http/docs/rx30/nasftp.sh
/www/http/docs/rx30/nasftpd.sh
/www/http/docs/rx30/rsync.sh
/www/http/docs/rx30/rsyncd.sh
/www/http/docs/rx30/vgback.sh
[server@user rx30]$ tar Wdf test.tar.bz2 
tar: Read 4928 bytes from test.tar.bz2
tar: VERIFY FAILURE: 28 invalid headers detected
tar: Error exit delayed from previous errors
Code:
[server@user rx30]$ tar --diff -vf test.tar.bz2 /www/http/docs/rx30/*.sh
tar: /www/http/docs/rx30/autoftp.sh: Not found in archive
tar: /www/http/docs/rx30/autoftpd.sh: Not found in archive
tar: /www/http/docs/rx30/back.sh: Not found in archive
tar: /www/http/docs/rx30/connect.sh: Not found in archive
tar: /www/http/docs/rx30/freespc.sh: Not found in archive
tar: /www/http/docs/rx30/modemflash.sh: Not found in archive
tar: /www/http/docs/rx30/nasftp.sh: Not found in archive
tar: /www/http/docs/rx30/nasftpd.sh: Not found in archive
tar: /www/http/docs/rx30/rsync.sh: Not found in archive
tar: /www/http/docs/rx30/rsyncd.sh: Not found in archive
tar: /www/http/docs/rx30/vgback.sh: Not found in archive
tar: Error exit delayed from previous errors
yet if i open and expand the tarball the files are there exactly as you would expect

Code:
server@user rx30]$ mkdir test
[server@user rx30]$ mv test.tar.bz2 test
[server@user rx30]$ cd test/
[server@user test]$ ls -l
total 16
-rw-rw-r-- 1 web web 15168 May  6 16:05 test.tar.bz2
[server@user test]$ tar -xjvf test.tar.bz2 
www/http/docs/rx30/autoftp.sh
www/http/docs/rx30/autoftpd.sh
www/http/docs/rx30/back.sh
www/http/docs/rx30/connect.sh
www/http/docs/rx30/freespc.sh
www/http/docs/rx30/modemflash.sh
www/http/docs/rx30/nasftp.sh
www/http/docs/rx30/nasftpd.sh
www/http/docs/rx30/rsync.sh
www/http/docs/rx30/rsyncd.sh
www/http/docs/rx30/vgback.sh
i can see that the tarball is preserving the directory tree and i am thinking this could be causing both the -W and the --diff to fail. What can i do about this?
 
Old 05-06-2012, 04:54 PM   #2
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Original Poster
Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
found this set of arguements and they do exactly what I want, but they create a larger file called 'W' why?

Code:
tar cvfW test.tar.bz2 /www/http/docs/rx30/*.sh
oh and when i cat W, it has all of the code from the *.sh scripts in it, what gives with that?
 
Old 05-06-2012, 05:34 PM   #3
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,630

Original Poster
Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
so to test it i did the following code and ran into a snag:

Code:
#!/bin/bash

###  This is a test of creating a tarball, verifying the tarball
###  then encrypting the tarball, before i delete all extra files
###  created in the process.

### Setting variables

tarfilename=test.tar.bz2
HOMEDIR="/www/http/docs/rx30/"
LOG="/www/http/docs/rx30/test.log"


###  Function calls from back2 script. 

### function to create the tar file
#####################################

TAR()

{
	tar cvjf ${tarfilename} ${HOMEDIR}*.sh  >> ${LOG} 
}

### Check, verify, and encrypt tarball
#####################################

checkTar ()

{

tar cvfW ${tarfilename} ${HOMEDIR}*.sh >> ${LOG}
if [ $? != 0 ]
then
	echo "Files have changed while compressing, data may be corrupt, or script was run in NO_KILL modes." | tee -a ${LOG}
else

tar tfj ${tarfilename} &> tar2; bzerr="$?"; echo ${bzerr} > bz-check.list

echo "Verifying compressed data." | tee -a ${LOG}
VERSTAT=`cat bz-check.list`

	if [ ${VERSTAT} -eq 0 ]
	then
		echo "Verification of compressed data was successfull." | tee -a ${LOG}
	else
		echo "Compressed data appears to be corrupt.  Error ${VERSTAT}." | tee -a ${LOG}
		exit 1
	fi
fi
    echo "Encrypting ${tarfilename}" | tee -a ${LOG}
    openssl des3 -a -salt -in ${tarfilename} -out ${tarfilename}.enc -pass pass:xxxxxxxxxx
    echo "${tarfilename}.enc Encrypted" | tee -a ${LOG}
	NEWTAR=${tarfilename}.enc

# to decrypt: openssl des3 -a -d -salt -in 2011-12-20.tar.bz2.enc -out 2011-12-20.tar.bz2 -pass pass:xxxxxxxxxx

}

###  Calling functions

TAR
checkTar

echo "Cleaning up ${tarfilename}, ${NEWTAR}, and W" | tee -a ${LOG}
	echo "removing ${tarfilename}" | tee -a ${LOG}
		rm -rf ${tarfilename}
	echo "removing W" | tee -a ${LOG}
		rm -rf W
exit;
when i run the tar cvjf foo.tar.bz2 dir/ then tar cvfW foo.tar.bz2 dir/ manually then echo $? i get a 0 as i would expect, why is the script saying i have something other then 0 as an output?
 
Old 05-12-2012, 07:42 PM   #4
dru8274
Member
 
Registered: Oct 2011
Location: New Zealand
Distribution: Debian
Posts: 105

Rep: Reputation: 37
Quote:
Originally Posted by lleb View Post
but they create a larger file called 'W' why?

Code:
tar cvfW test.tar.bz2 /www/http/docs/rx30/*.sh
oh and when i cat W, it has all of the code from the *.sh scripts in it
This is a long-shot, and I could be wrong. But tar normally expects the -f option to be followed by the output filename. Except that in your example, the -f option is immediately followed by W. So perhaps tar has misconstrued W as your desired output filename?

If that is the case, then it can be fixed by reordering the options in your tar command with the -W before the -f, to something like...

Code:
tar -cvWf test.tar.bz2 /www/http/docs/rx30/*.sh
 
Old 05-12-2012, 10:06 PM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,959

Rep: Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268Reputation: 1268
Quote:
Originally Posted by lleb View Post
found this set of arguements and they do exactly what I want, but they create a larger file called 'W' why?

Code:
tar cvfW test.tar.bz2 /www/http/docs/rx30/*.sh
oh and when i cat W, it has all of the code from the *.sh scripts in it, what gives with that?
If that is exactly the command line you ran, then what you describe shouldn't have happened. But, if the actual command line was
Code:
tar -cvfW test.tar.bz2 /www/http/docs/rx30/*.sh
(note the "-" introducing the option letters), then that would indeed create an archive file named "W" and include within that archive the file "test.tar.bz2" and files matching "/www/http/docs/rx30/*.sh" (and incidentally, not do the checking you thought was happening).

For historical reasons, tar supports two different styles for the single-letter options. The "old" style (no "-") and the more modern (with a leading "-") style look very similar, but options that take arguments are parsed very differently in the two styles. I suggest you read the info page for tar and pay particular attention to the section titled, "The Three Option Styles".
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i decompress this tar.tar file? hmmm sounds new.. tar.tar.. help ;) kublador Linux - Software 14 10-25-2016 03:48 AM
"Invalid tar magic" error msg. when I try to tar ldmud *.tar file in DSL pixxi451 Linux - Newbie 4 07-04-2010 09:32 AM
How to create .diff.gz/.dsc/.orig.tar.gz from a downloaded tar.gz application? frenchn00b Linux - General 4 05-18-2008 10:09 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 03:53 AM


All times are GMT -5. The time now is 08:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration