代碼:
#####################################
#
# DATABASE LOCK CHECK
#
#####################################
function Database_Lock_Check()
{
DB_LOCK_CHK=`lsof $package_install_path/ini/YourDBName.db |wc -c`
if [ $DB_LOCK_CHK -ne 0 ]; then
LOCK_COUNT=0
while [ $LOCK_COUNT -le 10 ]
do
echo $(date "+%b %d %H:%M:%S") "Database in use, wait 5 seconds before continuing..." | tee -a $package_install_path/event_log.txt
sleep 5
DB_CHK_LOCK=`lsof $package_install_path/ini/YourDBName.db |wc -c`
if [ $DB_CHK_LOCK -eq 0 ]; then
break
else
(( LOCK_COUNT++ ))
fi
done
if [ $LOCK_COUNT -eq 11 ]; then
echo $(date "+%b %d %H:%M:%S") "Database in locked, please contact YourName support window." | tee -a $package_install_path/event_log.txt
exit 0
fi
fi
}