Tar command fails


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tar command fails
# 8  
Old 12-07-2015
Quote:
Originally Posted by Don Cragun
Did you remove the export.tar.gz created by your first run before running again using ../export.tar.gz as the output file?

Did you try using the find pipeline I suggested in post #4 in this thread?
Yes I did remove the export.tar.gz created by the first run

---------- Post updated at 12:41 AM ---------- Previous update was at 12:37 AM ----------

I also tried the pipe command to exclude the *.tar.gz file but looks like it is being processed by the command as well.

Code:
"tar: ./export.tar.gz: file changed as we read it"

$ find . ! -name export.tar.gz | tar -cpzf export.tar.gz --files-from -

tar: ./export.tar.gz: file changed as we read it

---------- Post updated at 12:44 AM ---------- Previous update was at 12:41 AM ----------

Quote:
Originally Posted by Aia
File names can have the same name, but not the same path (location where they leave)

Example of two files with the same name
Code:
$ tree
.
├── dir1
│   └── sumang24.file
└── dir2
    └── sumang24.file

Creating a tar.gz file outside the directory sumang24
Code:
$ tar cpvzf ../sumang24.tar.gz *
dir1/
dir1/sumang24.file
dir2/
dir2/sumang24.file

Now, checking the content of sumang24.tar.gz
Code:
$ tar tf sumang24.tar.gz
dir1/
dir1/sumang24.file
dir2/
dir2/sumang24.file

For further understanding, you might need to post some more information.
Please, post the following:
  • The result of pwd before issuing the command
  • The output entries shown by the command tar tf export.tar.gz for only those two files you say they are the same.
  • The exact command that you used to tar and gzip.
  • And any clear explanation of what you expected but it was not so.
Here is a sample output from

Code:
tar tf sumang24.tar.gz

-rw-r--r-- user/user 33935 2015-12-05 13:41 ./File1.xml
-rw-r--r-- user/user 33935 2015-12-05 13:41 ./File1.xml


Last edited by Don Cragun; 12-07-2015 at 03:07 AM.. Reason: Add CODE and ICODE tags again.
# 9  
Old 12-07-2015
Quote:
Originally Posted by sumang24
[...]

I also tried the pipe command to exclude the *.tar.gz file but looks like it is being processed by the command as well.

"tar: ./export.tar.gz: file changed as we read it"

$ find . ! -name export.tar.gz | tar -cpzf export.tar.gz --files-from -

tar: ./export.tar.gz: file changed as we read it
[...]
Actually, this is happening because find is returning the current directory as well. If you do a find . ! -name export.tar.gz the first result is .
This might work.
Code:
find . ! -name export.tar.gz ! -name . | tar -cpzf export.tar.gz --files-from -

This User Gave Thanks to Aia For This Post:
# 10  
Old 12-07-2015
OK: I have kicked off the command suggested by you again

Code:
$ find . ! -name export.tar.gz ! -name . | tar -cpzf export.tar.gz --files-from -

Thanks!

Last edited by Don Cragun; 12-07-2015 at 03:05 AM.. Reason: Add CODE tags again.
# 11  
Old 12-07-2015
Quote:
Originally Posted by sumang24
[...]

tar tf sumang24.tar.gz

-rw-r--r-- user/user 33935 2015-12-05 13:41 ./File1.xml
-rw-r--r-- user/user 33935 2015-12-05 13:41 ./File1.xml
I do believe one of these is a link.

Quote:
OK: I have kicked off the command suggested by you again
I am sorry, but it appears that it would create links as well and you are going to see what it appears to be the same file several times.

A better suggestion would have been
tar cpzf ../export.tar.gz .

Or perhaps even
Code:
tar cpzf export.tar.gz /dir/dir1/dir2

without the original trailing *, from a different directory than /dir/dir1/dir2

Last edited by Aia; 12-07-2015 at 02:47 AM..
This User Gave Thanks to Aia For This Post:
# 12  
Old 12-07-2015
From: /dir/dir1

Code:
$ tar cpzf export.tar.gz /dir/dir1/dir2
tar: Removing leading `/' from member names

Is that OK that it is removing leading `/' from member names?

Last edited by Don Cragun; 12-07-2015 at 03:04 AM.. Reason: Add CODE and ICODE tags again.
# 13  
Old 12-07-2015
Quote:
Originally Posted by sumang24
From: /dir/dir1

Code:
$ tar cpzf export.tar.gz /dir/dir1/dir2
tar: Removing leading `/' from member names

Is that OK that it is removing leading `/' from member names?
Yes, it is more than OK. If not when you extract the archive it would overwrite the original /dir/dir1/dir2 directory, if exists, instead of extracting it in the current directory as dir/dir1/dir2

Now, if you really, would like to preserver the full path, and overwrite the original path when extracting, then you use the P flag
# 14  
Old 12-07-2015
Quote:
Originally Posted by sumang24
OK: I have kicked off the command suggested by you again

Code:
$ find . ! -name export.tar.gz ! -name . | tar -cpzf export.tar.gz --files-from -

Thanks!
The above command still gave me single files.
The output looks like:
-rw-r--r-- user/user 33935 2015-12-05 13:41 ./File1.xml
-rw-r--r-- user/user 67306 2015-12-04 20:43 ./File2.xml
-rw-r--r-- user/user 39804 2015-12-05 15:01 ./File3.xml

---------- Post updated at 02:18 AM ---------- Previous update was at 02:16 AM ----------

The output of the following command:

tar -ztvf export.tar.gz

---------- Post updated at 02:22 AM ---------- Previous update was at 02:18 AM ----------

Quote:
Originally Posted by Aia
Yes, it is more than OK. If not when you extract the archive it would overwrite the original /dir/dir1/dir2 directory, if exists, instead of extracting it in the current directory as dir/dir1/dir2

Now, if you really, would like to preserver the full path, and overwrite the original path when extracting, then you use the P flag
Looks like this command
$ tar cpzf export.tar.gz /dir/dir1/dir2

Is creating duplicates. I see the tarfile size has outgrown (by 1G ) the tarfile created via
find . ! -name export.tar.gz ! -name . | tar -cpzf export.tar.gz --files-from -
This User Gave Thanks to sumang24 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Cybersecurity

Use command 2 incase command 1 fails

I try to fire grep command on remote servers using ssh like below: sshpass -p mypassword ssh -t user1@mach2 "grep -e word1 -e word2 /var/out.txt" The issue is that i wish to run the same grep command which searches for multiple strings in a file on remote servers with different Operating... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. Shell Programming and Scripting

Script to check one command and if it fails moves to other command

Input is list of Server's, script is basically to remove old_rootvg, So it should check first command "alt_rootvg_op -X old_rootvg" if it passes move to next server and starts check and if it fails moves to other command "exportvg old_rootvg" for only that particular server. I came up with below,... (6 Replies)
Discussion started by: aix_admin_007
6 Replies

3. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

4. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

5. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

6. AIX

Find command fails in crontab

Hi , I imported find command I have on my hp-ux server to clean up the /tmp of my new IBM AIX servers. Though, the commands always fails in the cron but if I past it at the prompt, it works find. I tried with at jobs and regular 'find' . Could anyone tell me what I am doing wrong? Many... (4 Replies)
Discussion started by: cforget2810
4 Replies

7. Shell Programming and Scripting

tar command dont tar to original directory

HI, if I have a tarfile called pmapdata.tar that contains tar -tvf pmapdata.tar -rw-r--r-- 0/0 21 Oct 15 11:00 2009 /var/tmp/pmapdata/pmap4628.txt -rw-r--r-- 0/0 21 Oct 14 20:00 2009 /var/tmp/pmapdata/pmap23752.txt -rw-r--r-- 0/0 1625 Oct 13 20:00 2009... (1 Reply)
Discussion started by: borderblaster
1 Replies

8. Shell Programming and Scripting

unzip command fails in ssh

I'm trying to run a set of commands on a remote machine using ssh in a shell script. One of the commands is unzip. But when the execution reaches this command, the script fails with an error that unzip is not found. Below is the code and the error snippet. sourceDir=$1 ; filename=$3 ; destDir=$2... (4 Replies)
Discussion started by: farahzaiba
4 Replies

9. AIX

AIX: chpath command fails

Hi Guys, i'm having trouble changing the path-priority. Now both priorities are 1 as you can see in the lspath-output. Any ideas why the chpath command fails? # chpath -l hdisk3 -p fscsi1 -a priority=10 Method error (/etc/methods/chgdisk): 0514-080 Invalid routine argument... (4 Replies)
Discussion started by: raba
4 Replies

10. UNIX for Advanced & Expert Users

at command fails

hi, all the user on my machine can't launch at job anymore. they all got the message "error in message send" each time they launch something using the at command. i tried to empty the job queue but the error message is still there. What can I do ? Thanks (1 Reply)
Discussion started by: a329743
1 Replies
Login or Register to Ask a Question