Operating System - HP-UX
1752364 Members
5787 Online
108787 Solutions
New Discussion

Re: ftp script can't rename the file

 
vz7r1x
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 4
Dennis Handly
Acclaimed Contributor

Re: ftp script can't rename the file

>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.

 

James R. Ferguson
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...

vz7r1x
Regular Advisor

Re: ftp script can't rename the file

Thanks James and Dennis. It resolved my problem.

Dennis Handly
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.