tar command with compress option...

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers tar command with compress option...
# 1  
Old 10-10-2002
tar command with compress option...

Hi !

i have to write a script that archivs homes not used since 3 years.
First, my script gathers the users that are concerned, using the following command :

ll -lt /home/*/.sh_history | egrep '2000|1999|1998|1997' | awk '{print $3}'

i obtain a list like this :


Now i want to archiv each homes using for==>do,done with a tar (with compress option) in it....

Can someone give me the syntax i should use...i am not good at procedure writing...

# 2  
Old 10-11-2002
Well, your tar command will be along the lines of:

tar -czf /home/user_n /place4backup/user_n_home.tar.gz

You could substitute locations or user names with variables containing those details!

I'll need more time to think up the for==>do loop; I'm a bit better at Perl! I'm sure that someone here in this forum will post the for==>do loop construct for you!
# 3  
Old 10-11-2002
for loop

You can redirect the output of users to a file. Then do something like this.

for name in `cat file.1`
echo "starting tar of" $name
tar <somthing here>
something else here
echo "tar finished for " $name
done 2> error.log

Just off the top of my head. A for loop is very powerful if you can use repetitive code.

# 4  
Old 10-11-2002
You can do this :

for name in `ll -lt /home/*/.sh_history | egrep '2000|1999|1998|1997' | awk '{print $3}' `
echo "starting tar of" $name
tar <something here>
something else here
echo "tar finished for " $name
done 2> error.log


ll -lt /home/*/.sh_history | egrep '2000|1999|1998|1997' | awk '{print $3}' | while read name
echo "starting tar of" $name
tar <something here>
something else here
echo "tar finished for " $name
done 2> error.log

If the version of your tar command donīt have the "-z" option, you can make a FIFO file (name pipe) with the mknod command.

Like this :

mknod backup_file_p p
gzip < backup_file_p > backup_file_p.gz &
tar -cvf backup_file_p /home/user_x
\rm backup_file_p

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compress a tar file to smaller size

I have a tar file with name DTT012_GP_20140207.tar and many more with different names of different sizes ranging from 1GB to 4GB. Now my requirement is to extract/not extract these files and then divide it into various parts of size 500MB and save it with different names and then compress... (5 Replies)
Discussion started by: Shaibal_bp
5 Replies

2. UNIX for Dummies Questions & Answers

Compress 1st 20 Large different File using tar

Sorry guys.. dont know where to put this.. currently I am cleaning up system dump on our aix machine and I wanted to set zero the 1st 20 large file but before doing that I wanted to create some backup. is there any command that can compress all these file same time? tar syntax file? ... (2 Replies)
Discussion started by: thermometer
2 Replies

3. UNIX for Dummies Questions & Answers

Executing a tar command with the --exclude option in a Debian shell script.

Hi All, I am trying to execute the following tar command with two --exclude options to suppress extract of the two directories specified. Do I need to single quote the directory paths ?? Many thanks for your help. The relevant code excerpt from the script is: cd /var/www/${SITE} ... (7 Replies)
Discussion started by: daveu7
7 Replies

4. Shell Programming and Scripting

tar and compress in one step

I know there is a way to tar up directory and sub-directories and have it compressed all in one command but but the syntax escapes me. I seem to re-call something like this: tar -cvf /tmp/file.tar - | compress ? Can somebody please provide me with the syntax on how to tar/compress and... (6 Replies)
Discussion started by: BeefStu
6 Replies

5. Shell Programming and Scripting

Archive directory script with tar/compress

Hi all I need to write a script that archives all files with a certain date in the filename, to another location. It has to run on a AIX using tar/compress or another standard AIX tool. The directory will have x files, each prefixed with a date like yyyymmdd_desc.csv. I need all to... (7 Replies)
Discussion started by: AIXfrog
7 Replies

6. UNIX for Advanced & Expert Users

UNIX: Command to compress folder and all files into a tar

I am trying to grab a folder and all the folders and files underneath it and send it from one computer to another. I basically want to compress the whole folder into a tar, tgz, or zip file so that it can be sent as one file. is there a command to compress a folder and all its contents into a tar... (7 Replies)
Discussion started by: kane4355
7 Replies

7. UNIX for Dummies Questions & Answers

Compress the file using Tar command

Hi, When i am tar the file particular ,csv file format in a folder i am receiving the error Command: tar cf New_data.tar /new/file/mari/getdata/small/*.xml Arguements too long But sometimes i am able to compress other folder but the tar folder contains all the file format and... (10 Replies)
Discussion started by: marivinay
10 Replies

8. Shell Programming and Scripting

compress directories with .tar extension

hi guys.. Since am a bit new to shell scripting, can anyone help me with this problem please.. i've been struggling with it since 2 days. :( I have a directory lets say myFolder and within it I have sub directories let say myFolder1.tar, myFolder2, myFolder3, etc. I need to write a shell... (12 Replies)
Discussion started by: kanexxx
12 Replies

9. Shell Programming and Scripting

Search, Tar and Compress in one line

Hi all, I am supposed to collect a huge amount of log files from a unix system (HP-UX) onto a local system. The log files are not in one place, but they are scattered all over the Unix server. The unix server has only limited space, so that I can not create a tar file first and then compress it.... (4 Replies)
Discussion started by: bluesky099
4 Replies

10. UNIX for Advanced & Expert Users

tar and compress

I need to compress and tar a couple files in a directory, but I also want the original files unchanged, ie if I compress a1.cpp , then a1.cpp becomes a1.cpp.z, but what I want after running the compress utility is to have both a1.cpp as it is and a1.cpp.z and then tar a1.cpp.z to an... (4 Replies)
Discussion started by: muru
4 Replies
Login or Register to Ask a Question