Prevent multiple instances of sleep_weather.sh from running at once

This commit is contained in:
Collin Simpson 2020-08-02 18:38:49 -04:00 committed by xunoaib
parent 4f3bf8a9be
commit eeb19aba41

View file

@ -4,8 +4,19 @@
fahrenheit=$1
LOCKFILE=/tmp/.dracula-tmux-weather.lock
ensure_single_process()
{
# check for another running instance of this script and terminate it if found
[ -f $LOCKFILE ] && ps -p "$(cat $LOCKFILE)" -o cmd= | grep -F " ${BASH_SOURCE[0]}" && kill "$(cat $LOCKFILE)"
echo $$ > $LOCKFILE
}
main()
{
ensure_single_process
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
$current_dir/weather.sh > $current_dir/../data/weather.txt
@ -20,6 +31,8 @@ main()
break
fi
done
rm $LOCKFILE
}
#run main driver function