Sponsored Content
Top Forums Shell Programming and Scripting zipping functionality (tar) not working as expected Post 302597819 by agama on Sunday 12th of February 2012 10:15:25 AM
Old 02-12-2012
The -c option on your tar command is causing a new file to be created with each invocation. When there are more files in your input file than can be placed on the command line xargs will invoke tar multiple times, and with each invocation tar creates a new file. What you are seeing in the final tar file is the set of files that were placed on the command line to tar with the last invocation.


To solve this problem, just remove the -c option:


Code:
xargs <$index  tar -rf $archived_file

You also don't need to use cat; xargs can read from stdin so the index file can be redirected in making the process more efficient.


EDIT: One more thought...
Because the -r option always appends if the target file exists, you should always remove the file before executing your tar command:

Code:
rm -f $archived_file     # ensure it doesn't exist
xargs <$index  tar -rf $archived_file


Last edited by agama; 02-12-2012 at 11:21 AM.. Reason: additional thought
These 2 Users Gave Thanks to agama For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

which not working as expected

Hello. Consider the following magic words: # ls `which adduser` ls: /usr/sbin/adduser: No such file or directory # Hmmm... Then: # ls /usr/sbin/adduser /usr/sbin/adduser # Now what? Unforunately this little sniippet is used in my debian woody server's mysql pre install script.... (2 Replies)
Discussion started by: osee
2 Replies

2. Shell Programming and Scripting

ls not working as expected within ksh

Hi, I use the command ls a\b\c\*.txt from the command line on HP UNIX and it works fine - It lists all files matching *.txt in the a\b\c directory When embeded in a ksh script `ls a\b\c\*.txt` it does not work - I get *.txt not found (even though there are files) I tried... (10 Replies)
Discussion started by: GNMIKE
10 Replies

3. UNIX for Dummies Questions & Answers

tar'ing and zipping files

If I have a directory /directory1 and want to tar and zip everything in it into a file new_tar.tar.gz on disk (not tape) How can I do it? I tried tar -cv /new_tar.tar /directory1/* But I got an error: tar: /dev/rmt/0: No such device or address (4 Replies)
Discussion started by: FredSmith
4 Replies

4. Shell Programming and Scripting

tar: 0511-194 Reached end-of-file before expected.

Hello everyone! I wrote a script for backing up a folder. It goes fine but today it started to spit out this error, when a folder is taring: tar: 0511-194 Reached end-of-file before expected. I didn't make any changes! - OS: UNIX AIX ibm 3 - the folder I'm trying to tar is 11Gb large... (4 Replies)
Discussion started by: Funky_ass
4 Replies

5. UNIX for Dummies Questions & Answers

zipping all the tar files to singlr file in directory

Hi, i have more than 300 tar files in directory and i want to zip all tar files to single file. could anybody tell me the command since i know how to do zip for single tar file: bash-3.00$gzip 2008_11_10.tar bash-3.00$ pwd /oracle1/archivebackup in this directory i have lot files... (2 Replies)
Discussion started by: prakash.gr
2 Replies

6. Shell Programming and Scripting

Why this is not working in expected way?

total=0 seq 1 5 | while read i ; do total=$(($total+$i)) echo $total done echo $totalThis outputs: 1 3 6 10 15 0whereas I am expecting: 1 3 6 10 15 15My bash version: (4 Replies)
Discussion started by: meharo
4 Replies

7. UNIX for Dummies Questions & Answers

-atime not working as expected

I need to sort through a volume that contains video files by access time and delete files that have not been accessed over x days. I have to use the access time as video files are originals that do not get modified, just read Testing commands on a local test folder... $ date Wed Sep 28... (10 Replies)
Discussion started by: canon273
10 Replies

8. UNIX for Dummies Questions & Answers

Nohup not working as expected

Hi. I am trying to start a script on my router that will execute even if i log off. To execute the script I write: nohup ./dslconnection > dslstat.out 2>&1 & It starts the job: 21968 admin 1604 S /bin/ash ./dslconnection The problem is that when I log back in the job has been... (6 Replies)
Discussion started by: sebcou
6 Replies

9. Shell Programming and Scripting

Script not working as expected

Hi, I have prepared a script and trying to execute it but not getting expected output. Could you please help and advise what is going wrong. "If else" part in below script is not working basically. I am running it on HP-UX. for i in slpd puma sfmdb do echo "******\t$i\t*******" echo... (10 Replies)
Discussion started by: sv0081493
10 Replies

10. UNIX for Advanced & Expert Users

Test -e not working as expected (by me)

I ran into the following and still do not understand entirely the rationale behind this. If someone could explain why things are as they are I'd be thankful. The following was tested on AIX 7.1 with ksh88, but i suspect that to be ubiquitous. In an installation routine i had to create a set of... (6 Replies)
Discussion started by: bakunin
6 Replies
GIT-TAR-TREE(1) 						    Git Manual							   GIT-TAR-TREE(1)

NAME
git-tar-tree - Create a tar archive of the files in the named tree object SYNOPSIS
git tar-tree [--remote=<repo>] <tree-ish> [ <base> ] DESCRIPTION
THIS COMMAND IS DEPRECATED. Use git archive with --format=tar option instead (and move the <base> argument to --prefix=base/). Creates a tar archive containing the tree structure for the named tree. When <base> is specified it is added as a leading path to the files in the generated tar archive. git tar-tree behaves differently when given a tree ID versus when given a commit ID or tag ID. In the first case the current time is used as modification time of each file in the archive. In the latter case the commit time as recorded in the referenced commit object is used instead. Additionally the commit ID is stored in a global extended pax header. It can be extracted using git get-tar-commit-id. OPTIONS
<tree-ish> The tree or commit to produce tar archive for. If it is the object name of a commit object. <base> Leading path to the files in the resulting tar archive. --remote=<repo> Instead of making a tar archive from local repository, retrieve a tar archive from a remote repository. CONFIGURATION
tar.umask This variable can be used to restrict the permission bits of tar archive entries. The default is 0002, which turns off the world write bit. The special value "user" indicates that the archiving user's umask will be used instead. See umask(2) for details. EXAMPLES
git tar-tree HEAD junk | (cd /var/tmp/ && tar xf -) Create a tar archive that contains the contents of the latest commit on the current branch, and extracts it in /var/tmp/junk directory. git tar-tree v1.4.0 git-1.4.0 | gzip >git-1.4.0.tar.gz Create a tarball for v1.4.0 release. git tar-tree v1.4.0^{tree} git-1.4.0 | gzip >git-1.4.0.tar.gz Create a tarball for v1.4.0 release, but without a global extended pax header. git tar-tree --remote=example.com:git.git v1.4.0 >git-1.4.0.tar Get a tarball v1.4.0 from example.com. git tar-tree HEAD:Documentation/ git-docs > git-1.4.0-docs.tar Put everything in the current head's Documentation/ directory into git-1.4.0-docs.tar, with the prefix git-docs/. GIT
Part of the git(1) suite Git 1.7.10.4 11/24/2012 GIT-TAR-TREE(1)
All times are GMT -4. The time now is 05:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy