LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Script to find tar archives, read tar file contents, output content to an index file. (http://www.linuxquestions.org/questions/linux-general-1/script-to-find-tar-archives-read-tar-file-contents-output-content-to-an-index-file-858374/)

bluesword1969 01-24-2011 10:54 AM

Script to find tar archives, read tar file contents, output content to an index file.
 
Just doing some tests, making directories into tar files:

find . -type d -links 2 -exec tar cvf {}.tar {} \;

Works fine.

I have been trying to do:

$ find . -type f -name \*.tar -execdir tar tvf {} > {}.lst \;

The result:

tar: Error is not recoverable: exiting now
tar: ./Outbox.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./Notes.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./cert8.db: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./tasks.ics: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./system.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./categories.xml: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./key3.db: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./signature-1: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./signature-0: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./calendar.ics: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./system.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./secmod.db: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: ./gvfs-metadata.tar: Cannot open: No such file or directory

unSpawn 01-24-2011 07:08 PM

Among other things (-iname, choosing between -execdir and using fixed or user-supplied full paths with loops, extension checking, getting rid of error messages) you need proper quoting as in
Code:

find /some/path/ -type f -iname \*.tar.\* 2>/dev/null|egrep -ie "\.(bz|bz2|gz|xz|z)$" 2>/dev/null|while read FILE; do tar -tf "${FILE}" > "${FILE}.ndx" 2>/dev/null; done
?

bluesword1969 01-25-2011 10:46 AM

Quote:

Originally Posted by unSpawn (Post 4236599)
Among other things (-iname, choosing between -execdir and using fixed or user-supplied full paths with loops, extension checking, getting rid of error messages) you need proper quoting as in
Code:

find /some/path/ -type f -iname \*.tar.\* 2>/dev/null|egrep -ie "\.(bz|bz2|gz|xz|z)$" 2>/dev/null|while read FILE; do tar -tf "${FILE}" > "${FILE}.ndx" 2>/dev/null; done
?

I'm mostly a hardware guy, so please go easy on me.

Yes, I still have much to learn.

And, thanks!

unSpawn 01-25-2011 11:00 AM

Quote:

Originally Posted by bluesword1969 (Post 4237262)
please go easy on me.

I did, didn't you notice? :-]


Quote:

Originally Posted by bluesword1969 (Post 4237262)
Yes, I still have much to learn.

And, thanks!

NP, that's what we're here for. Here's some help if you need it BTW:
Code:

function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html
http://www.tldp.org/LDP/abs/html/
http://wooledge.org/mywiki/BashFAQ?action=show&redirect=BashFaq; }


bluesword1969 02-07-2011 12:15 PM

Quote:

Originally Posted by unSpawn (Post 4237282)
I did, didn't you notice? :-]



NP, that's what we're here for. Here's some help if you need it BTW:
Code:

function help() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html
http://www.tldp.org/LDP/abs/html/
http://wooledge.org/mywiki/BashFAQ?action=show&redirect=BashFaq; }


Thank you for your help. With the nice kick start above, I was able to create some of my own scripts that did the job just nice.


All times are GMT -5. The time now is 10:46 PM.