I have a script (moves log file in backup dir) located in a shared folder that runs in ServerA. It is working as expected. I am planning to run this script in several servers, ie ServerB, ServerC, ServerD. However, since the script is located in a shared folder, it may cause issue if all servers will run this script simultaneously. Can you please advise? I am thinking of putting a flag that checks if the script is being used. I am not yet sure on how.
Script
TIMESTAMP=`date "+%Y.%m.%d-%H.%M"`
LOGS="$(cat Apps.txt)"
LOGSUFFIX=".log"
APPLOGS_DIR="/APPSDIR"
BACKUP_DIR="/BACKUPDIR"
for LOG in ${LOGS}
do
if [ -f "${APPLOGS_DIR}/${LOG}${LOGSUFFIX}" ]
then
gzip "${APPLOGS_DIR}/${LOG}${LOGSUFFIX}"
mv "${APPLOGS_DIR}/${LOG}${LOGSUFFIX}.gz" "${BACKUP_DIR}/${LOG}_${TIMESTAMP}.gz"
echo "$Logs moved to backup directory "
else
echo "No logs"
fi
done
bash
running onServer{A B,C,D}
will READ the script. No conflict there. Deconflicting simultaneous runs can involve lock files (man -k lock
), or use of$(hostname)
in filenames or directory names. – waltinator Oct 13 '20 at 16:17