I have written a plsql procedure using utl file to create files in the temp directory in Unix.
I am sending the names of the files to a shell script to mail these files and delete after mailing from temp directory, it is working good but when two people running the same request with the same files, the files are replaced and deleted by the first program and the second program not having any files in the directory to mail.
I decided to create file names_request_id to make file names unique, but my actual requirement is to get the files with the same name with out request_id to person who is receiving email.
I created Incompatibility for the program with the same program but they want me to take away the incompatibility to save time.
What other options do I have?
For your reference i copied my whole shell script and added ####### symbol to denote the location of the code to be modified.
The files are moved to the created directory and the file names have reuest_id-filename.extension so that request_id and the '-' must be removed and the actual filename should be there. name of the file in the database: 23456663-abcd.pdf required name of the filename : abcd.pdf
param=`echo $*`
#getting input values
echo "params : $param"
v_temp=`echo $param | cut -d '"' -f 1 `
v_temp=`echo $v_temp | cut -d '=' -f 2 `
v_temp=`echo $v_temp | cut -d ' ' -f 1 `
#now v_temp has the request_id
v_temp=MUILT_EMAIL3-$v_temp
echo "temp file is : $v_temp"
#split the parameter string with " as seperator
v_email_list=`echo $param | cut -d '"' -f 8 `
v_file_list=`echo $param | cut -d '"' -f 10 `
v_subject=`echo $param | cut -d '"' -f 12 `
v_mail_content=`echo $param | cut -d '"' -f 14 `
v_reply_to=`echo $param | cut -d '"' -f 16 `
v_delete_attachment_files=`echo "$1"|cut -d'"' -f18`
v_outputfile_path=`echo "$1"|cut -d'"' -f20`
v_outputfile=`echo "$1"|cut -d'"' -f22`
v_request_id=`echo "$1"|cut -d'"' -f24`
#v_rename_file=`echo $param | cut -d '"' -f 24 `
echo "email list :" $v_email_list
echo "file list :" $v_file_list
echo "subject :" $v_subject
echo "mail_content :" $v_mail_content
echo "reply_to :" $v_reply_to
echo "delete_attachment_files :" $v_delete_attachment_files
echo "outputfile_path :" $v_outputfile_path
echo "outputfile :" $v_outputfile
echo "request_id :" $v_request_id
v_email_list=`echo $v_email_list |tr ";" " "`
v_file_list=`echo $v_file_list |tr ";" " "`
pwd
cd /
mkdir /tmp/$v_request_id
cp $v_outputfile_path /tmp/$v_request_id/$v_outputfile
mv /tmp/$v_request_id* /tmp/$v_request_id/
cd /tmp/$v_request_id/
###### this is the place i need to rename the files that are moved to a request_id dir
################# mv -- "34178248-2640006.pdf" "${34178248-2640006.pdf}"
v_mail_content =`basename $v_mail_content`
cat $v_mail_content > /tmp/${v_temp}.tmp
echo "File List : $v_file_list"
for i in ${v_file_list}; do
echo "File to attach before parsing $i"
v_attachment_name=`echo $i |awk '{ if ( index($1,":")> 0) { print substr($1,index($1,":")+1) } }'`
v_attachment_file=`echo $i |awk '{ if ( index($1,":")> 0) { print substr($1,1,index($1,":")-1) } }'`
echo "Checking attachment name after parse :"$v_attachment_name
if [ "$v_attachment_name" = '' ]
then
v_attachment_name=`basename $i`
v_attachment_file=$i
echo "base name is " $v_attachment_name
fi
/usr/bin/uuencode $v_attachment_file $v_attachment_name >> /tmp/${v_temp}.tmp
done
echo "Loop done"
if [ "${v_reply_to}" = '' ]
then
mailx -s "${v_subject}" "${v_email_list}" < /tmp/${v_temp}.tmp
#echo "something" | mailx -s "${v_subject}" ${v_email_list} < /tmp/${v_temp}.tmp
else
mailx -r "${v_reply_to}" -s "${v_subject}" "${v_email_list}" < /tmp/${v_temp}.tmp
#echo "something" | mailx -r "${v_reply_to}" -s "${v_subject}" ${v_email_list} < /tmp/${v_temp}.tmp
fi
echo "mailing done"
#delete the temporary files
echo "deleting file /tmp/${v_temp}.tmp"
rm /tmp/${v_temp}.tmp
if [ "${v_delete_attachment_files}" = 'Y' ]
then
echo "deleting attached files -start "
#Loop through to identify all the attachments and delete
for i in ${v_file_list}; do
echo $i
v_attachment_name=`echo $i |awk '{ if ( index($1,":")> 0) { print substr($1,index($1,":")+1) } }'`
v_attachment_file=`echo $i |awk '{ if ( index($1,":")> 0) { print substr($1,1,index($1,":")-1) } }'`
echo "Check :"$v_attachment_name
if [ "$v_attachment_name" = '' ]
then
v_attachment_name=`basename $i`
v_attachment_file=$i
echo "base name is " $v_attachment_name
fi
echo "deleting file $v_attachment_file"
rm $v_attachment_file
done
#End Loop through to identify all the attachments and delete
fi
echo "rm done"