Issue with tar command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with tar command
# 1  
Old 04-14-2015
Issue with tar command

Hi all,

I have a folder that I am trying to tar ut is leading to unexpected results.

Ive written a script that find a certain number of files(logs) with specific names older than 14 days, moves them to a folder and compresses that folder.

Code:
_ARCHIVE=/opt/test/archived_logs
_DAILY=/opt/test/archived_logs/logs_$(date +"%Y_%m_%d")


cd $_BASE/$i/log
find $_BASE/$i/log \( -name "*out.*" -o -name "*log.*" -o -name "event-runtime-*" -o -name "event-[0-9]*" -o -name "upload-trace-*" -o -name "pmm-[0-9]*" \) -mtime +14 -exec mv {} $_DAILY \;

tar -zcvf $_DAILY.tar.gz $_DAILY

The find commands returns me a number of log files and places them into $_DAILY .

The problem that I am seeing is that when I untar the file created by the end, I have to go down further directories like:

Code:
[user@server archived_logs]$ ls -tlrh
total 12K
-rw-rw-r-- 1 user group 5.8K Apr 14 15:05 logs_2015_04_14.tar.gz
drwxrwxr-x 3 user group 4.0K Apr 14 15:55 opt

[user@server archived_logs]$ pwd
/opt/ericsson/archived_logs

[user@server archived_logs]$  cd opt/test/archived_logs/logs_2015_04_14

[user@server archived_logs]$ file opt/ericsson/archived_logs/logs_2015_04_14
opt/test/archived_logs/logs_2015_04_14: ASCII English text, with very long lines

how can I remove the path (opt/test/archived_logs) created ?

Secondly the initial folder contains a number of log files. But when I untar the file, I only have one file in it rather than a number of log files.

Any idea what I am doing wrong ?
# 2  
Old 04-15-2015
tar by default extracts to the cwd extended by the original path with the leading / removed. There may be an option to modify that, c.f. man tar.
Are you sure that _DAILY exists and is a directory when doing your find? If not, every new file will overwrite the last one leaving one single file behind.
# 3  
Old 04-15-2015
try like this

Code:
tar -zcvf $_DAILY.tar.gz --exclude="$_DAILY.tar.gz" -C $_DAILY .

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tar and un-tar issue

In AIX 5.3, I have these directories: /lms /lms/w_standard /lms/d_admin /lms/b_common /lms/b_prodbus /lms/d_prod /lms/d_prod/ccldir /lms/d_prod/ccluserdir /lms/d_prod/config /lms/d_prod/data /lms/d_prod/log /lms/d_prod/ocd /lms/d_prod/print /lms/d_prod/temp /lms/reg... (7 Replies)
Discussion started by: Daniel Gate
7 Replies

2. 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

3. UNIX for Dummies Questions & Answers

TAR issue

Hello all, I was attempting to create a tar file via this command: tar cpf 20100529.tar | find . -name *20100529* Attempt to create archive of no files. Nothing dumped. which produced a list of several files in the .tar file but in the end the file was: -rw-r--r-- 1 xxx_xxxx users ... (9 Replies)
Discussion started by: riker
9 Replies

4. 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

5. Shell Programming and Scripting

Tar file issue.

Hi all, I have couple of files I need to tar and put in some client server could some body help me the basic understanding of tarring files please It would be a great help. regards Anwar (4 Replies)
Discussion started by: Haque123
4 Replies

6. Shell Programming and Scripting

using tar via su in a script issue !!!

I am trying to implement the below command in my shell script su - $PROCESS -c `tar -tvf $file|tee -a $LOG/$file.log` The idea is to get the tar output on the screen and at the same time it should put the output in the log file. Problem is: 1) I donot get the output on the screen. 2)... (3 Replies)
Discussion started by: kpatel786
3 Replies

7. Shell Programming and Scripting

Tar archive issue

Hi, I make a tar archive: tar -czvf /path_to/cucu.tar.gz /path/dir_to_archive/ In the archive the /path/dir_to_archive/ is maintained for every file. I need that the archive to be made without the /path/dir_to_archive/ to contain only the files in /path/dir_to_archive/. Thanks,... (4 Replies)
Discussion started by: potro
4 Replies

8. Shell Programming and Scripting

tar issue

frnds, I compressed some files on the basic of $date var. $date contains todays date in some specific format.. also my files are in different directories... now, I m doing. tar -cvf archive.tar /root/abc/*$date* /root/wxv/123/*$date* /var/*$date* this creates archive.tar for me.. ... (4 Replies)
Discussion started by: clx
4 Replies

9. HP-UX

Tar command issue

I made tar file having file names more character( up to 50). When i extract file in Linux it extracts fine.. but in HPUX all file name which are more than 24 are trimed to 24 characters. i m using "tar -xvf xx.tar" i read some O and N option for New posix and Old but didnt got. :confused: ... (2 Replies)
Discussion started by: ajayyadavmca
2 Replies

10. UNIX for Dummies Questions & Answers

tar /dev/dat issue

Hi, I am trying to write to a dat tape, using HP UX 10.20 tar: cannot open /dev/dat not mounted ? ioscan ? if so, then where ? suggestions ? thanks simon (6 Replies)
Discussion started by: simon2000
6 Replies
Login or Register to Ask a Question