LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 04-05-2010, 03:00 PM   #1
venkimuck
LQ Newbie
 
Registered: Apr 2010
Posts: 2

Rep: Reputation: 0
Talking Shell Script for FTP and gzip


I want to be able to write a shell script for downloading files (only *.tar extension) from multiple folders (the sub folder's names may vary) in a FTP site and be able to untar them and then gzip them and then move them to the real folder. Any help appreciated.
 
Old 04-05-2010, 03:37 PM   #2
naman.jandial
Member
 
Registered: Jan 2010
Posts: 30

Rep: Reputation: 16
If I am not wrong, what you want is:

1.) Download a tar file from an ftp site.
2.) Untar them
3.) Tar them a again with gzip and save them to a particular location.

Though I am new to Linux but will still try. Please do post, if I was rigt or wrong in my approach, this will help to understand the concept better.

vim test.sh
Code:
wget http://ftp.domainname.com/filename.tar
tar -xvf filename.tar
for NAME in $(tar -tvf filename.tar)
tar -C /mydirectory -zcvf newfilename.tar $NAME
I hope this works, if it doesn't and you get the proper code, please do let me know.

Naman

Last edited by naman.jandial; 04-05-2010 at 03:47 PM.
 
Old 04-05-2010, 03:46 PM   #3
naman.jandial
Member
 
Registered: Jan 2010
Posts: 30

Rep: Reputation: 16
Or you can also do this:

Code:
wget http://ftp.domainname.com/filename.tar
tar -xvf filename.tar > downloaded_tar_files
for NAME in $(cat downloaded_tar_files)
tar -C /mydirectory -zcvf newfilename.tar $NAME

Last edited by naman.jandial; 04-05-2010 at 03:47 PM.
 
Old 04-05-2010, 03:47 PM   #4
venkimuck
LQ Newbie
 
Registered: Apr 2010
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for trying to answer my question.

The ftp site has login and pwd (not annonymous login)

Also, I do not know the file name or number of files. I want to be able to find out and download all the *.tar files existing in a directory structure (that too does not have the name constant).

Once I untar the files, they are with .Z extension (compressed files). I have to uncompress them using gzip -d <file name>.
 
Old 04-05-2010, 04:36 PM   #5
naman.jandial
Member
 
Registered: Jan 2010
Posts: 30

Rep: Reputation: 16
Try this then:

Code:
wget ftp://ftp.domainname.com/*.tar.gz
enter password when prompted: 
ls *.tar.gz > filenames
for NAME in $(cat filenames)
mkdir $NAME
tar -C $NAME -zxvf $NAME.tar.gz
tar -C $NAME -zcvf newfilename.tar.gz $NAME/*
GOD I hope it works, got a bit confused, while formulating it. LOL
 
  


Reply

Tags
automation, ftp, gzip, naman, script


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
Need Ftp Shell script vishal_titre Programming 3 02-03-2009 03:03 AM
automated FTP shell script RedOctober45 Linux - Software 1 01-09-2008 08:58 AM
Auto ftp shell script mcrosby Linux - Newbie 9 06-27-2007 06:09 AM
ftp through shell script HSN Programming 24 02-23-2007 03:18 PM
shell script for ftp javier_ccs Programming 7 07-18-2006 11:02 PM


All times are GMT -5. The time now is 03:45 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration