BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

ftp script can't rename the file

Regular Advisor

ftp script can't rename the file

Hi,

I am running a ftp script to xfer file. Script is expected to rename file upon transmission with current date extension but it does not work. I am attaching my sample script for your review. can you please give some input?

 

Server>more carrier_gen.txt
open 192.168.50.17
user robertx Password123
put /var/opt/oracle/log/carrier_gen.log carrier_gen.txt_'(date+%m\%d\%y)'
bye

 

Server> more New_Feed_ftp.sh
#!/usr/bin/sh
#
ftp -i -n < /home/SystemScripts/carrier_gen.txt*

 

When I put the file I am trying to put it in a different name with current date as an extension to avoid overwriting. I am using back tic around (date+%m\%d\%y).

 

Thanks

 

Thanks

4 REPLIES
Acclaimed Contributor

Re: ftp script can't rename the file

[ Edited ]

>can you please give some input?

 

You need to use a here doc:

 

#!/usr/bin/sh
ftp -i -n <<EOF
open 192.168.50.17
user robertx Password123
put /var/opt/oracle/log/carrier_gen.log carrier_gen.txt_$(date +%m%d%y)
bye EOF

 

Now a real shell will evaluate $(date +%m%d%y) before it is read.

 

Acclaimed Contributor

Re: ftp script can't rename the file


vz7r1x wrote:

When I put the file I am trying to put it in a different name with current date as an extension to avoid overwriting. I am using back tic around (date+%m\%d\%y).

 


You don't appear to have used backticks (at least my copy-and-paste) suggests not.  You don't need to escape the "%" characters and in fact you don't want to; and you need a space after 'date' and before the formatting instructions.  Instead of backticks, use the POSIX $(...) syntax:

 

# put /var/opt/oracle/log/carrier_gen.log carrier_gen.txt_$(date +%m%d%y)

 

Regards!

 

...JRF...

Regular Advisor

Re: ftp script can't rename the file

Thanks James and Dennis. It resolved my problem.

Acclaimed Contributor

Re: ftp script can't rename the file

>Thanks James and Dennis. It resolved my problem.

 

If you are happy with your answers, please click on the kudos stars and consider marking a solution.