Prevent multiple instances of sleep_weather.sh from running at once
This commit is contained in:
parent
4f3bf8a9be
commit
eeb19aba41
1 changed files with 14 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue