Hi there,
Firstly, I have no experience with shell scripts so would really appreciate some help.
I have the following shell script that is causing some problems:
moveit()
{
[ ${DEBG} = "1" ] && set -x
if [ -f ${JOURNAL}.${ASOF_DATE} ]
then
DOUBLE_DELIVERY=$(grep "${SW_ID}.*${P_DIR}.*${TARGET_NAME}.*${N_OF_REC}.*${SZ_KI}" ${JOURNAL}.${ASOF_DATE})
fi
if [ ! -z $DOUBLE_DELIVERY ]
then
LOC_TAG="ASIFUNC_01"
ERROR_MSG="File $2 was sent already"
msg_error ${ERROR_MSG} && temp_err_handler FI_DBLE
fi
LOC_TAG="ASIFUNC_02"
ERROR_MSG="Destination $2 already exists"
ls "$2" >/dev/null 2>&1 && msg_error ${ERROR_MSG} && temp_err_handler FI_EXST
msg_message "\"$1\" has been moved to \"$2\""
mv "$1" "$2"
if [ "$?" -ne "0" ]
then
LOC_TAG="ASIFUNC_03"
ERROR_MSG="Can't move file $1 to $2"
msg_error ${ERROR_MSG}
temp_err_handler MV_FILE
else
chmod 660 $2
chgrp ggearch $2
STATUS_MSG="OK"
USEFUL_VALUE=`echo $ASOF_DATE | grep '^20..[0-1][0-9][0-3][0-9]'`
if [ ! -z $USEFUL_VALUE ]
then
if [ ! -f ${JOURNAL}.${ASOF_DATE} ]
then
createFile ${JOURNAL}.${ASOF_DATE}
fi
echo "${SW_ID} ${P_DIR} ${TARGET_NAME} ${N_OF_REC} ${SZ_KI} ${NOW} ${SCRIPT_INDX} ${P_ASIFTYP}">> ${JOURNAL}.${ASOF_DATE}
else
msg_message "Could not generate a Journal file for $2"
fi
logStatus
fi
}
#
The problem is, the current setup is causing problems when we have duplicate archiving retrievals, as I can see the log file being written does not allow duplicate entries with the same. I need to change this by creating a sequential number and renaming the file with say _1, then the next file can be called _2. This would enable us to retrieve an archiving period as many times as we need to without the errors.
I would propose to delete the first statement:
if [ -f ${JOURNAL}.${ASOF_DATE} ]
then
DOUBLE_DELIVERY=$(grep "${SW_ID}.*${P_DIR}.*${TARGET_NAME}.*${N_OF_REC}.*${SZ_KI}" ${JOURNAL}.${ASOF_DATE})
fi
if [ ! -z $DOUBLE_DELIVERY ]
then
LOC_TAG="ASIFUNC_01"
ERROR_MSG="File $2 was sent already"
msg_error ${ERROR_MSG} && temp_err_handler FI_DBLE
fi
then I would place the command in the lower part of the code. However, I am unsure of any shell commands, I have written in bold below the logical explanation of what I want to achieve, if there's someone that can help with the code it would be greatly appreciated.
else
chmod 660 $2
chgrp ggearch $2
STATUS_MSG="OK"
USEFUL_VALUE=`echo $ASOF_DATE | grep '^20..[0-1][0-9][0-3][0-9]'`
if [ ! -z $USEFUL_VALUE ]
then
if [ ! -f ${JOURNAL}.${ASOF_DATE} ]
then
createFile ${JOURNAL}.${ASOF_DATE}._1
fi
echo "${SW_ID} ${P_DIR} ${TARGET_NAME} ${N_OF_REC} ${SZ_KI} ${NOW} ${SCRIPT_INDX} ${P_ASIFTYP}">> ${JOURNAL}.${ASOF_DATE}
else
if file name ends in "_1"
then rename file (_1 + 1) i.e. _2
if file name ends in "_2"
then rename file (_2 + 1) i.e. _3 and so on.....
end
msg_message "Could not generate a Journal file for $2"
fi
logStatus
fi