How to Concatenate timestamp to filename
841964Apr 7 2011 — edited Apr 7 2011Hi Gurus,
I've one requirement where I need to fetch file of zero bytes from remote server, rename the file by suffixing current date timestamp and again ftp the same file to remote location.
For this I've written below mentioned script:
CURR_TIMESTAMP=`_date +%Y%m%d%H%M`
ftp -v -n 10.60.188.11<< EOF
user appltest appltest
lcd /u01/oratest
cd /usr/tmp
bin
prompt n
mget EPO_RPO000*.NODATA
mdelete EPO_RPO000*.NODATA
bye
EOF
cd /u01/oratest
ls -l EPO_RPO000*.NODATA
if [ $? -ne 0 ]
then
echo "There are no NODATA files"
else
for file in `ls -1 EPO_RPO000*.NODATA`
do
a_file=$(basename $file .NODATA).NODATA.ACK
echo "Filename: $a_file"
ftp -v -n 10.60.188.11<< EOF
user appltest appltest
lcd /u01/oratest
cd /usr/tmp
bin
prompt n
put $a_file
bye
done
fi
In this script for example my file name is "EPO_RPO000201012201_20101221142055.NODATA" then I need to rename the file to
"EPO_RPO000201012201_20101221142055_20110407182445.NODATA.ACK"
Means I need to suffix the file name with current date timestamp before extension of the file, and again suffix '.ACK' after extension of file.
I was capable of suffixing after extension(for eg : "EPO_RPO000201012201_20101221142055.NODATA.ACK"), but I don't know how to concatenate timestamp before extension of file.
Thanks in advance for your suggestions.
Regards
Nagendra
Edited by: 838961 on Apr 7, 2011 2:56 AM