Merge pull request #56 from xunoaib/master

Prevent multiple instances of sleep_weather.sh from running simultaneously
This commit is contained in:
Dane Williams 2020-08-02 17:52:06 -07:00 committed by GitHub
commit fbc02789b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,12 +4,23 @@
fahrenheit=$1 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() main()
{ {
ensure_single_process
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
$current_dir/weather.sh > $current_dir/../data/weather.txt $current_dir/weather.sh > $current_dir/../data/weather.txt
while tmux has-session &> /dev/null while tmux has-session &> /dev/null
do do
$current_dir/weather.sh $fahrenheit > $current_dir/../data/weather.txt $current_dir/weather.sh $fahrenheit > $current_dir/../data/weather.txt
@ -20,6 +31,8 @@ main()
break break
fi fi
done done
rm $LOCKFILE
} }
#run main driver function #run main driver function