Script help - TAR


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script help - TAR
# 1  
Old 12-21-2011
Script help - TAR

*****CAN'T CHANGE THE TOPIC NAME******** I'm using "zip" instead

Hi. I'm trying to make my script use "zip" and i want it to compress all the files in a directory to individual zip files... but i can't really figure out how. i have googled around. tried some different things... but i can't get it to work. It doesn't do anything after "exit" when i run the script.

And yes the rest of the script works as it should.

script:

Code:
#!do not change below
cd $LOCAL
ftp -n $HOST <<SCRIPT
user $USER $PASSWD
prompt
binary
cd $REMOTE
mget -f $FILES
exit
cd $LOCAL
zip *.txt
SCRIPT


Last edited by vYN; 12-21-2011 at 10:53 PM..
# 2  
Old 12-21-2011
Try...
Code:
for i in *.txt; do zip "${i%.txt}.zip" "$i"; done

# 3  
Old 12-22-2011
Quote:
Originally Posted by Ygor
Try...
Code:
for i in *.txt; do zip "${i%.txt}.zip" "$i"; done

OMG it worked. thx... sorry to ask... how do i remove the txt files it just ziped.

rm *.txt ?
# 4  
Old 12-22-2011
Quote:
Originally Posted by vYN
OMG it worked. thx... sorry to ask... how do i remove the txt files it just ziped.

rm *.txt ?
Yes, but careful. That will delete all the txt files in current directory.
# 5  
Old 12-22-2011
Once the zip operation is completed, ( after successful completion ), the below command will delete that .txt file

Code:
 
for i in *.txt; do zip "${i%.txt}.zip" "$i" && rm "$i" ; done

# 6  
Old 12-22-2011
OKey. Thanks for all the help with this little issue. and it's now solved ^^
# 7  
Old 12-22-2011
Or use zip -m
From man zip...
Quote:
-m
Move the specified files into the zip archive; actually, this deletes the target directories/files after making the specified zip archive. If a directory becomes empty after removal of the files, the directory is also removed. No deletions are done until zip has created the archive without error. This is useful for conserving disk space, but is potentially dangerous so it is recommended to use it in combination with -T to test the archive before removing all input files.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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. 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. Shell Programming and Scripting

Need help with tar script

The following script is supposed to look at a list of files and folders and tar them all up. Ofcourse you have to strip off everything to the left of the file or folder to tar only that object. My problem is that when I do that my script no longer knows how to find the file or folder. Is there a... (0 Replies)
Discussion started by: mj12net_brian
0 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. 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

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

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

8. UNIX for Advanced & Expert Users

Tar utility (untar a .tar file) on VxWorks

Hi All Can someone pls guide me if there any utility to compress file on windows & uncompress on vxworks I tried as - - compressed some folders on windows ... i created .tar ( to maintain directory structure ) and compressed to .gz format. - on VxWorks i have uncompressed it to .tar... (1 Reply)
Discussion started by: uday_01
1 Replies

9. UNIX for Dummies Questions & Answers

tar in a script

I am trying to write a simple script where I tar a few files and send them to tape The code looks like this: tar -cvf archive/tam/*20080507* archive/sam/*20080507* source/delta/*20080507* This runs fine from the command line but when i try to run this in a script I get an end of tape... (3 Replies)
Discussion started by: zapper222
3 Replies

10. Shell Programming and Scripting

how to write script in tar

i have the script.in this script comprees formatlike tar and insert to another directory and another sever.and how to write this process in script . iam new for unix how to do this process. please helpmea naveen.g (1 Reply)
Discussion started by: naveeng.81
1 Replies
Login or Register to Ask a Question