Merge pull request #56 from xunoaib/master
Prevent multiple instances of sleep_weather.sh from running simultaneously
This commit is contained in:
commit
fbc02789b4
1 changed files with 14 additions and 1 deletions
|
@ -4,12 +4,23 @@
|
|||
|
||||
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
|
||||
|
||||
|
||||
while tmux has-session &> /dev/null
|
||||
do
|
||||
$current_dir/weather.sh $fahrenheit > $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