tmux2k/scripts/sleep_weather.sh

45 lines
1.1 KiB
Bash
Raw Normal View History

2022-08-09 06:28:34 +05:30
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
#wrapper script for running weather on interval
fahrenheit=$1
location=$2
fixedlocation=$3
LOCKFILE=/tmp/.tmux2k-tmux-weather.lock
DATAFILE=/tmp/.tmux2k-tmux-data
2023-03-29 14:52:27 +05:30
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
2022-08-09 06:28:34 +05:30
}
2023-03-29 14:52:27 +05:30
main() {
ensure_single_process
2022-08-09 06:28:34 +05:30
2023-03-29 14:52:27 +05:30
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2022-08-09 06:28:34 +05:30
2023-03-29 14:52:27 +05:30
if [ ! -f $DATAFILE ]; then
printf "Loading..." >$DATAFILE
fi
2022-08-09 06:28:34 +05:30
2023-03-29 14:52:27 +05:30
"$current_dir"/weather.sh >$DATAFILE
2022-08-09 06:28:34 +05:30
2023-03-29 14:52:27 +05:30
while tmux has-session &>/dev/null; do
"$current_dir"/weather.sh "$fahrenheit" "$location" "$fixedlocation" >$DATAFILE
if tmux has-session &>/dev/null; then
sleep 1200
else
break
fi
done
2022-08-09 06:28:34 +05:30
2023-03-29 14:52:27 +05:30
rm $LOCKFILE
2022-08-09 06:28:34 +05:30
}
#run main driver function
main