Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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?
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...
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".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.