我对这部分脚本有疑问。我需要比较两个变量。此外,我已经设置了一些功能,用于修剪我需要比较的名称。
任何人都可以帮我找到错误吗?
checkLock ()
{
DATE_LCK=`date '+%Y%m%d'`
FILE_LOCK=$DATE_LCK"_"LCK"_"$ENTITY".lock"
cd $LOCK
if [ -f "$FILE_LOCK" ]
then
for i in `ls -rt *.lock `
do
INPUTFILE=$i
LOCK_ENTITY_NAME= `echo "$INPUTFILE"`
#LOCK_ENTITY_NAME= `echo "${INPUTFILE}" | head -n 1 | cut -d "_" -f3 | cut -d "." -f1`
if [ $ENTITY == $LOCK_ENTITY_NAME ]
then
echo `date '+%a %b %d %H:%M:%S :'` "File Lock exist for the entity selected process interrupted" >> $LOG_FILE
exit 1
else
echo `date '+%a %b %d %H:%M:%S :'` "Create File lock for the Entity selected" >> $LOG_FILE
touch $LOCK/$FILE_LOCK
fi
done
else
echo `date '+%a %b %d %H:%M:%S :'` "Create File lock for the process" >> $LOG_FILE
touch $LOCK/$FILE_LOCK
fi
}
答案 0 :(得分:0)
使用checkLock ()
{
# Consider using lowercase vars
DATE_LCK=$(date '+%Y%m%d')
FILE_LOCK="${DATE_LCK}_LCK_${ENTITY}.lock"
# Is ${LOCK} set to some value?
cd ${LOCK}
if [ -f "${FILE_LOCK}" ]; then
# you do not need the ls
for LOCK_ENTITY_NAME in *.lock; do
if [ "${ENTITY}" = "${LOCK_ENTITY_NAME}" ]; then
echo "$(date '+%a %b %d %H:%M:%S') : File Lock exist for the entity selected process interrupted" >> ${LOG_FILE}
exit 1
else
echo "$(date '+%a %b %d %H:%M:%S) : Create File lock for the Entity selected" >> ${LOG_FILE}
# You already did "cd ${LOCK}", the touch doesn't need the path again,
# you are still in the [ -f "${FILE_LOCK}" ] loop, the lockfile exists (you are only changing the modification date)
touch ${FILE_LOCK}
fi
done
else
echo "$(date '+%a %b %d %H:%M:%S) : Create File lock for the process" >> ${LOG_FILE}
touch ${FILE_LOCK}
fi
}
(一个等号)测试变量。
一些更改:
if [ -f "${ENTITY}" ]
使用此代码,您可以看到更多内容以进行改进。现在您正在测试子目录中的所有文件,并且您正尝试触摸每个文件* .lock文件的$ {FILE_LOCK}。
你可以不使用function mylog {
echo "$(date '+%a %b %d %H:%M:%S') : $*" >> ${LOG_FILE}
}
# and call the function with
mylog "File Lock exist for the entity selected process interrupted"
的for循环。
也许你想要一个像
val results = task.getAssignedFiles map {
file: File => Future[Result] {
<heavy computation>
}
}