How to ftp and rename file in Unix
841964Mar 30 2011 — edited Apr 2 2011Hi Gurus,
I've one requirement where I need to rename the file extension to .xml and read the file.
Here I am pasting my sample code what I've tried
#get the file from remote server
#
ftp -v -n 10.60.17.111<< EOF
user user user
cd /u01/oratest/gebiz_processed
lcd /usr/tmp
bi
get GEBIZ_ACS_RPO000*.ACK
#mdelete $file
#mv GEBIZ_ACS_RPO000*.* /u01/appltest
#get GEBIZ_SUPP.xml
bye
EOF
echo
cd /u01/oratest/gebiz_processed
file =$(ls -rt GEBIZ_ACS_RPO000*.ACK | tail -1)
if [ -r "$file" ];
then
#
#HERE ONLY I NEED TO RENAME THE ABOVE .ACK EXTENSION TO .XML
#
a_file=$(basename $file .ack)
b_file="'$file'"
c_file=$file
echo "Filename: $a_file $b_file" && echo
output=`sqlplus -s /nolog <<-EOT
set pages 0 feed off
whenever sqlerror exit failure;
connect xgbzprod/xgbzprod
exec XGBZ_GLSEGM_XMLTAG_PROC($b_file);
`
echo $output
mv $c_file /u01/oratest/gebiz_inbound
fi
This is my whole script, Steps in this I am performing like :
1> Get the file from another server where the full file name I don't have, since it is suffixed with timestamp, so I called this one like this GEBIZ_ACS_RPO000*.ACK
2> During FTP time, once I copy to my server then I need to delete file GEBIZ_ACS_RPO000*.ACK on that server, I've full permission. How to write that one.
3> Then inside my server I need to change GEBIZ_ACS_RPO000*.ACK to GEBIZ_ACS_RPO000*.XML. How can I write this.
4> Changed extension file name I need to pass in my pl/sql script for processing, which I am taking care.
5> Inside GEBIZ_ACS_RPO000*.ACK, I've xml data only. So I need to change extension of the file to GEBIZ_ACS_RPO000*.XML
I tried to write like above mentioned but I am not getting successful and more over I am not able to rename the file. I know
with command
mv GEBIZ_ACS_RPO000*.ACK GEBIZ_ACS_RPO000*.xml
I can do that but I want it in program way.
Gurus, please help me how to write those steps, and correct me if I am doing wrong above.
Thanks in advance for your help.
Regards
Nagendra
Edited by: 838961 on Mar 30, 2011 12:22 AM