LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 01-01-2008, 10:24 AM   #1
shipon_97
Member
 
Registered: Oct 2005
Location: Bangladesh
Posts: 504

Rep: Reputation: 31
ftp with a script


Dear friend ,
I am going to create a customized ftp script . Scenario is stated below :

Suppose, I have two big size folder "test1" and "test2" . My mission is , Firstly i make those files as a "tar" file and then transfer the files to another machine using "ftp" protocol with time stamp facility (system date with time) .Script is :

==========================
Date1=`date +%d%b%Y`
Date=`date +%d%b%Y`.`date +%I`.`date +%M%p`
cd /test
tar -cvf test1_$Date.tar test1
tar -cvf test2_$Date.tar test2
ftp -i -v -n 192.168.10.1 <<END_FTP
user oracle oracle
binary
cd /tmp
mput test1_$Date.tar
mput test2_$Date.tar
bye
==============================

It works fine . this script create the file Like " test1_01Jan2008.08.10AM.tar " and "test2_01Jan2008.08.10AM.tar"

Now my problem is :
suppose file1 and file2 take 2 minutes to make "tar" file like following way :
"test1_01Jan2008.08.10AM.tar"
"test2_01Jan2008.08.10AM.tar"

In this situation , After two minutes my system date goes to 08:12AM . So that my next two lines
"mput test2_$Date.tar" and "mput test2_$Date.tar" are not executed . Because at that moment system date is 08:12AM , which are not matched with previous two lines .


Here in this stage i need urs help . Can any body plz give me any suggestions ........Waiting for kind reply ...


Another Question ,
Is it possible to ftp more than one file together ? Like following :

"test1_01Jan2008.* " or "test1_01Jan2008.tar* "

Last edited by shipon_97; 01-01-2008 at 10:48 AM.
 
Old 01-01-2008, 11:26 AM   #2
tommytomthms5
Member
 
Registered: Sep 2007
Distribution: debian based
Posts: 308

Rep: Reputation: Disabled
thats a hard one i think this belongs in the more advanced forums
 
Old 01-01-2008, 12:14 PM   #3
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
I created the following script
Code:
#!/bin/bash
Date1=`date +%d%b%Y`.`date +%I`.`date +%M%S%p`
Date2="`date +%d%b%Y`.`date +%I`.`date +%M%S%p`"
echo $Date1
echo $Date2
sleep 5
echo $Date1
echo $Date2
It produced the following output
Code:
[mymachine:~/lq/shipon_97]:./blah 
01Jan2008.01.0932PM
01Jan2008.01.0932PM
01Jan2008.01.0932PM
01Jan2008.01.0932PM
As you can see, the output is the same. What shell are you using? I get the same result if I use sh or ksh.
 
Old 01-01-2008, 12:31 PM   #4
tagno25
Member
 
Registered: Jun 2007
Posts: 53

Rep: Reputation: 15
try
Code:
Date1=`date +%d%b%Y`
Date2=`date +%d%b%Y`.`date +%I`.`date +%M%p`
cd /test
tar -cvf test1_$Date2.tar test1
tar -cvf test2_$Date2.tar test2
ftp -i -v -n 192.168.10.1 <<END_FTP
user oracle oracle
binary
cd /tmp
mput test1_$Date2.tar
mput test2_$Date2.tar
bye
 
Old 01-01-2008, 12:37 PM   #5
kzutter
Member
 
Registered: Nov 2007
Location: Carson City, NV USA
Distribution: Various, but always Debian based
Posts: 70

Rep: Reputation: 15
Cast your dated filename to a variable and then use the variable for the the filename.

Something like this:

Code:
Date=`date +%d%b%Y`.`date +%I`.`date +%M%p`
FILE1="test1_$Date.tar"
FILE2="test2_$Date.tar"
...
tar $FILE1 test1
tar $FILE2 test2
...
mput $FILE1
mput $FILE2
 
Old 01-02-2008, 02:03 AM   #6
shipon_97
Member
 
Registered: Oct 2005
Location: Bangladesh
Posts: 504

Original Poster
Rep: Reputation: 31
customized ftp command

Thx kzutter ,

Ur advice is very useful .

I have another issue . At the last stage of script , i add another two lines for removing the "tar" files from my local machine , Like follwoing :

Date1=`date +%d%b%Y`
Date2=`date +%d%b%Y`.`date +%I`.`date +%M%p`
cd /test
tar -cvf test1_$Date2.tar test1
tar -cvf test2_$Date2.tar test2
ftp -i -v -n 192.168.10.1 <<END_FTP
user oracle oracle
binary
cd /tmp
mput test1_$Date2.tar
mput test2_$Date2.tar
bye
rm -rf test1_$Date2.tar
rm -rf test2_$Date2.tar

But this script executes at the stage of "bye" , Next two lines are not executing . Now my question is , after "ftp" command, how can i execute another lines ?
 
Old 01-02-2008, 05:16 AM   #7
muazfarooqaslam
LQ Newbie
 
Registered: Dec 2007
Posts: 22

Rep: Reputation: 15
You might want to close the here file "END_FTP". Maybe something like this,

Date1=`date +%d%b%Y`
Date2=`date +%d%b%Y`.`date +%I`.`date +%M%p`
cd /test
tar -cvf test1_$Date2.tar test1
tar -cvf test2_$Date2.tar test2
ftp -i -v -n 192.168.10.1 <<END_FTP
user oracle oracle
binary
cd /tmp
mput test1_$Date2.tar
mput test2_$Date2.tar
bye
END_FTP
rm -rf test1_$Date2.tar
rm -rf test2_$Date2.tar
 
  


Reply



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
FTP Script tommytomato Linux - General 28 07-14-2006 05:16 AM
FTP script the_imax General 6 12-30-2005 01:27 AM
Urgent Help: Perl FTP Script Using NET::FTP xboxter Programming 8 05-16-2005 06:57 PM
Ftp script scialom Linux - Software 2 05-04-2004 03:03 PM
ftp script dlm4444 Linux - Networking 5 02-10-2004 11:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:44 AM.

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
Open Source Consulting | Domain Registration