Some help with tar options and syntax?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Some help with tar options and syntax?
# 1  
Old 05-29-2011
Some help with tar options and syntax?

I've got a script that's first copying a list of files into /etc/confbackups after running some other stuff, I'm having trouble with tar now though.

What I've got:
Code:
tar -cCf $date.$list.tar.gz /etc/confbackups *.conf

What I'm thinking this is supposed to do is create the archive as specified, move to directory then do that for all .conf files in that directory?

Any help appreciated! I'm not sure if I'm getting the order of my options right...
# 2  
Old 05-29-2011
You'll have to put the values that some options expect directly after the option itself. Also, you'll have to tell tar to compress the file, too. Try it as
Code:
tar -cz -f $date.$list.tar.gz -C /etc/confbackups *.conf

# 3  
Old 05-29-2011
Meh ionno, I tried what you've got and some other variations I just randomly got off google but no luck.

I keep getting:

tar: .tar.gz: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

It ~is~ actually making a copy of the file (in the directory the script's in though...) but it's lacking the .tar.gz extension although when I open it, it does seem to be encrypted...

This is what I have at the moment. The idea is when any md5 match fails that that file would be copied and compressed into /etc/confbackups...

Code:
#!/bin/bash
function report ()
{
cd /home/johan/pro1

	md5sum -c md5 2>/dev/null | awk -F '/FAILED/ { print $1 } '
	md5sum -c md5 | awk ' { print $1, $2 } ' > report.txt

		sudo chmod 777 /etc/confbackups
		chmod 770 report.txt
		chmod 770 *.conf
}

report

	list=`grep -v OK report.txt | awk ' { print $1 } ' | sed 's/:/ /'`;
	isodate=`date +%Y%m%d`;
	files=`grep -v OK report.txt`;

if [[ $files == *FAILED* ]];
then
	cp $list /etc/confbackups
	tar -cz -f $isodate.$list.tar.gz -C /etc/confbackups $list
else
	echo "Hash Matched"
fi

I tried using $list up here instead, *.conf was actually doing everything but the failed file which was weird (still not compressed though...)
# 4  
Old 05-30-2011
I think I see your problem here. In $list, you have a list of files, separated by space, for example
Code:
$ cat report.txt
conf1.conf: OK
conf2.conf: FAILED
conf3.conf: OK
conf4.conf: OK
conf5.conf: OK
conf6.conf: OK

$ list=$( grep -v OK report.txt | awk ' { print $1 } ' | sed 's/:/ /' )
$ echo ">>"$list" <<"
>>conf2.conf  <<

And then you plug that into the tar command, not only as the list of files to be put into the archive, but as part of the name, too:
Code:
$ echo tar -cz -f 20110530.$list.tar.gz -C /etc/confbackups $list
tar -cz -f 20110530.conf2.conf .tar.gz -C /etc/confbackups conf2.conf

That's the command line as tar would see it. Since spaces separate options, the space in the variable screws with the option order.

You only want to create a compressed copy of those files that have changed, right?
# 5  
Old 05-30-2011
Yeah thanks, I figured it all out today. Got my tar syntax way wrong got a helping hand for that and realized I had overthinked it waaaayyyyy too much. As far the bit with the sed, I only later realized that having an actual space in there actually replaced the colon in *.conf: with an actual space. So I fixed that bit myself at least. Smilie Thanks anyway!
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Do I need to extract the entire tar file to confirm the tar folder is fine?

I would like to confirm my file.tar is been tar-ed correctly before I remove them. But I have very limited disc space to untar it. Can I just do the listing instead of actual extract it? Can I say confirm folder integrity if the listing is sucessful without problem? tar tvf file1.tar ... (1 Reply)
Discussion started by: vivien_chu
1 Replies

2. UNIX for Dummies Questions & Answers

Dot and redirected output syntax in a tar command

Hi All, Please could anyone advise what the purpose of the dot syntax in the following command means: tar -cvf ${WORKING_BACKUP_ROOT}/${TAR_ARCHIVE_FILE} . >/${BACKUP_ROOT}/${ARCHIVE_LOG} Many thanks (2 Replies)
Discussion started by: daveu7
2 Replies

3. Ubuntu

Kernel boot options removed by fault, no boot options

Hello Everyone, First of all, I highly appreciate all Linux forum members and whole Linux community. http://forums.linuxmint.com/images/smilies/icon_wink.gif. I wish you the best for all of you ! I will try to be short and concise: I am using Linux Mint 10 for 2 months on 2 ws, and all went... (3 Replies)
Discussion started by: cdt
3 Replies

4. Shell Programming and Scripting

tar -C syntax question

I am writing a perl script to tar multiple files (in unix) from a given directory to a given output directory. I do NOT want the file path included in the tar, so I've flagged the -C option. Example: tar -cvf tar/1.tar -C htmp/source/ 1-1-1.xml However, I need to do this for a number of target... (3 Replies)
Discussion started by: michanjohns
3 Replies

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

6. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

7. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

8. UNIX for Dummies Questions & Answers

Syntax for tar command

I am trying to extract a file using tar. I cd'ed to the directory I wanted to start in. I had the tar file in the same directory. I executed tar xvf filename . It appeared that it was extracting into the directory the tar file was created from instead of into the directory I was in. How do I... (1 Reply)
Discussion started by: baunocj
1 Replies
Login or Register to Ask a Question