LinuxQuestions.org
Visit Jeremy's Blog.
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 04-27-2014, 01:15 PM   #1
Tadaen
Member
 
Registered: Sep 2005
Distribution: Arch
Posts: 207

Rep: Reputation: 39
Script failing with tar command.


Building myself some install scripts. This is giving me issues.

Code:
theming()
{
	if [ -d $1 ] ; then
		ls $1 | while read i ; do
			tar -xf $i -C $2
		done
	fi
}
Error output

Code:
tar: ilinux.tar.gz: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: simple-2.7.tar.gz: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
So the script is both detecting the tar files in the folder but saying they don't exist at the same time? The function is invoked as such in a while loop. This is how it is for testing purposes. Under actual use this would be done as root to insert icon packs / themes into the appropriate /usr/share/ directories.

Code:
theming ~/Debian/icons ~/icons
Please advise if have an idea.

Last edited by Tadaen; 04-27-2014 at 01:21 PM.
 
Old 04-27-2014, 01:37 PM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
It's not a simple tar file, but a tar then zipped file (see file extension i.e. tar.gz), so in addition to tar extraction options, use -z switch as well.

For instance, to extract a tar.gz file, use command:
Code:
# tar -zxvf ilinux.tar.gz
Accordingly make changes in your script.
 
Old 04-27-2014, 01:48 PM   #3
Tadaen
Member
 
Registered: Sep 2005
Distribution: Arch
Posts: 207

Original Poster
Rep: Reputation: 39
This is with z switch.
Code:
tar (child): ilinux.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
tar (child): simple-2.7.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
Code:
tar -xf ??.tar.gz -C /path/
Works from the command line.

*EDIT* I should redo the subject as files exist but don't exist?

Last edited by Tadaen; 04-27-2014 at 02:01 PM.
 
Old 04-27-2014, 01:57 PM   #4
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
http://mywiki.wooledge.org/BashGuide

For tips


Your problem is the ls $1 , you get a list of files, but not full path

You could do tar -xf ${1}/${i} .....

But using ls for this kind of thing is bad see link above

This should work for you
Code:
for tarball in ${1}/*.tar.gz;do
   tar -xf ${tarball} -C $2
done
Please note, only basic example, you may want/need to build some checks in, and deal with errors gracefully

Last edited by Firerat; 04-27-2014 at 02:00 PM.
 
1 members found this post helpful.
Old 04-27-2014, 06:01 PM   #5
Tadaen
Member
 
Registered: Sep 2005
Distribution: Arch
Posts: 207

Original Poster
Rep: Reputation: 39
Went ahead and altered my for statements using direct instead of ls. Won't be as recyclable as I liked but it is at least it will work out of the box on any debian based distros.

Thank you for looking and figuring it out.
 
  


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
[SOLVED] LFS 7.3--> tar xf lfs-bootscripts-20130123.tar.bz2 , bash : tar : command not found AkiraMizuki Linux From Scratch 3 06-01-2013 04:00 AM
tar-command not found while compiling glibc-libidn-2.7.tar.bz2 of lfs6.3 aditya_gpch Linux From Scratch 1 05-14-2008 12:27 AM
mount -o loop command failing in startup script for RH 5 dougkdp76 Linux - General 3 01-12-2008 12:04 PM
bash syntax when envoking tar command in python script tangle Programming 4 02-04-2006 04:22 PM
Bash backup script failing using tar and --newer option saldkj Programming 3 03-12-2005 01:03 PM


All times are GMT -5. The time now is 06:53 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