LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ftp with a script (https://www.linuxquestions.org/questions/linux-newbie-8/ftp-with-a-script-610359/)

shipon_97 01-01-2008 10:24 AM

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* "

tommytomthms5 01-01-2008 11:26 AM

thats a hard one i think this belongs in the more advanced forums

David1357 01-01-2008 12:14 PM

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.

tagno25 01-01-2008 12:31 PM

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


kzutter 01-01-2008 12:37 PM

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


shipon_97 01-02-2008 02:03 AM

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 ?

muazfarooqaslam 01-02-2008 05:16 AM

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 08:18 PM.