LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-03-2009, 06:39 AM   #1
hi_irf
LQ Newbie
 
Registered: Apr 2007
Posts: 15

Rep: Reputation: 0
Shell Script how to remove absolute paths from zip archive


Hi,

I need to write an bash script which works like it can copy files from remote machine through ssh to the server where script is running in zip format with the structure i want. I don't want to get absolute path in zip archive. Please let me know how it can be possible.

ssh source-ip-address zip backup.zip /home/dir1/test.txt /home/dir1/test/test2.txt

# /home/dir1/test2/txt is the source.

unzip -l backup.zip > list.txt

`cat list.txt`

# list.txt contains /home/dir1/test.txt /home/dir1/test/test2.txt

By default zip store absolute paths. While i don't want to store /home/dir1 & /home/dir2/ in zip archive. I need zip file in following format.

test.txt
test/test2.txt

I know it is possible if i can change working directory when creating zip but as i am creating zip through remote machine, don't know how to change working directory. like it doesn't works

ssh source-ip-address cd /home/dir1
ssh source-ip-address zip backup.zip test.txt test/test2.txt

Or is there anyway that i can zip the files from root path means not to include common path in archive i.e. /home/dir1

Thanks,
 
Old 10-03-2009, 06:59 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
Why use zip. Use a native unix format such as tar.

Here is how you can perform a backup, using tar and don't need to have the actual tar file produced:

tar -C / -cf - /home /usr /srv /bin /sbin | ssh user@host tar -C <backup_dir> -xvf -

This will create the subdirectories that you don't want but the -C <dir> option allows you to change the base directory to start from and restore to, which is similar to your question.

You could use cpio instead of tar.
Here is an example which copies the files to my home directory in my desktop, via ssh. While the work/list* files are listed, without the -d option, they are all created in the same directory.

ls index.html* work/list* | cpio --create -v | ssh hpmedia cpio -vi -

If you do start from a tar or cpio file, you can simply cat the archive file through the pipe.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Absolute and relative paths Gins Linux - General 6 11-08-2008 09:48 PM
Script to Add files to a Zip archive with out unzipping it !! prashix Programming 12 10-23-2007 10:19 AM
How about a shell script archive? Autocross.US LQ Suggestions & Feedback 2 12-05-2006 07:36 PM
relative/absolute paths in Java djgerbavore Programming 2 10-26-2004 09:01 PM
shell script - add file to archive ? xconspirisist Linux - Software 2 03-20-2004 04:27 PM


All times are GMT -5. The time now is 08:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration