0

Below is the LockFile part of my script. Lockfile should remove and recreate after 5 mins automatically as the script is set to run every 5mins to check to be sure the services on the server are running.

Lockfile is created but not removed after 5 mins.

#####################################################################################################
# will check if lock file exists, if not create it, or if lock file exists and
# is older than allowed time then delete lock file and try restart again.
#####################################################################################################
createLockFile(){

# check if the file exist already
if [ -f $LOCK_FILE_NAME ]
then
# see if older than 5 mins
if test "`find $LOCK_FILE_NAME -mmin +5`"
then
removeLockFile
else
# Lock file found, another instance of restart is running or lock file is less than allowed time.
exit 0;
fi
fi

touch $LOCK_FILE_NAME

} # End of createLockFile()

#####################################################################################################
## Descripton : will remove lock file, allowing future script runs.
#####################################################################################################
removeLockFile(){
A
echo  "removing LockFile"
rm $LOCK_FILE_NAME

} # End of removeLockFile()
Gordon Davisson
  • 11,036
  • 3
  • 27
  • 33
  • The script appears to be incomplete, since it never sets `LOCK_FILE_NAME` or runs `createLockFile`. Is it doing things in the correct order? Also, are you aware that `find ... -mmin +5` finds files modified *more* than 5 (i.e. 6 or more) minutes ago? – Gordon Davisson Oct 31 '19 at 17:53
  • What is the line with the singular `A` good for? – linux-fan Nov 08 '19 at 17:34

0 Answers0