ftp script can't rename the file (280 Views)
Reply
Regular Advisor
vz7r1x
Posts: 183
Registered: ‎12-05-2006
Message 1 of 5 (280 Views)

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

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,746
Registered: ‎03-06-2006
Message 2 of 5 (276 Views)

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.

 

Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 3 of 5 (274 Views)

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

Please use plain text.
Regular Advisor
vz7r1x
Posts: 183
Registered: ‎12-05-2006
Message 4 of 5 (253 Views)

Re: ftp script can't rename the file

Thanks James and Dennis. It resolved my problem.

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,746
Registered: ‎03-06-2006
Message 5 of 5 (244 Views)

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.

 

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation