Add IGNORE_EVENTS_WHILE_COMMAND_IS_RUNNING feature
This commit is contained in:
22
monitor.sh
22
monitor.sh
@@ -154,6 +154,23 @@ function wait_for_minimum_period {
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
function wait_for_command_to_complete {
|
||||
PID=$1
|
||||
|
||||
while ps -p $PID > /dev/null
|
||||
do
|
||||
sleep .1
|
||||
|
||||
if [[ "$IGNORE_EVENTS_WHILE_COMMAND_IS_RUNNING" == "1" ]]
|
||||
then
|
||||
# -t 0 didn't work for me. Seemed to return success with no RECORD
|
||||
while read -t 0.001 RECORD; do :; done
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
echo "$(ts) Starting monitor for $CONFIG_FILE"
|
||||
|
||||
tr -d '\r' < $CONFIG_FILE > /tmp/$NAME.conf
|
||||
@@ -193,7 +210,10 @@ do
|
||||
wait_for_minimum_period $last_run_time
|
||||
|
||||
echo "$(ts) Running command"
|
||||
$COMMAND
|
||||
$COMMAND &
|
||||
PID=$!
|
||||
last_run_time=$(date +"%s")
|
||||
|
||||
wait_for_command_to_complete $PID
|
||||
fi
|
||||
done <$pipe
|
||||
|
||||
@@ -26,3 +26,8 @@ MIN_PERIOD=10:00
|
||||
# In this example, we call a SageTV remote API to trigger a rescan of the imported media library. The command assumes
|
||||
# that we've installed the plugin called "sagex-services - SageTV Remote API Services".
|
||||
COMMAND="wget -nv -O /dev/null --auth-no-challenge http://sage:frey@192.168.1.102:8080/sagex/api?c=RunLibraryImportScan&1="
|
||||
|
||||
# This is a very good idea if your command modifies the WATCH_DIR in any way. You can easily trigger yourself because
|
||||
# most programs don't worry about checking the current state before making a change. e.g. chmod will set the mode of a
|
||||
# file even if it already has that mode.
|
||||
IGNORE_EVENTS_WHILE_COMMAND_IS_RUNNING=1
|
||||
|
||||
Reference in New Issue
Block a user