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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-01-2008, 10:24 AM
|
#1
|
Member
Registered: Oct 2005
Location: Bangladesh
Posts: 504
Rep:
|
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.
|
|
|
01-01-2008, 11:26 AM
|
#2
|
Member
Registered: Sep 2007
Distribution: debian based
Posts: 308
Rep: 
|
thats a hard one i think this belongs in the more advanced forums
|
|
|
01-01-2008, 12:14 PM
|
#3
|
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
Rep: 
|
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.
|
|
|
01-01-2008, 12:31 PM
|
#4
|
Member
Registered: Jun 2007
Posts: 53
Rep:
|
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
|
|
|
01-01-2008, 12:37 PM
|
#5
|
Member
Registered: Nov 2007
Location: Carson City, NV USA
Distribution: Various, but always Debian based
Posts: 70
Rep:
|
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
|
|
|
01-02-2008, 02:03 AM
|
#6
|
Member
Registered: Oct 2005
Location: Bangladesh
Posts: 504
Original Poster
Rep:
|
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 ?
|
|
|
01-02-2008, 05:16 AM
|
#7
|
LQ Newbie
Registered: Dec 2007
Posts: 22
Rep:
|
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
|
|
|
All times are GMT -5. The time now is 02:20 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|