Skip to content

Instantly share code, notes, and snippets.

@researcx
Created April 15, 2022 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save researcx/aac0fafa12ba6a8e3ed8c121c6efc73e to your computer and use it in GitHub Desktop.
Save researcx/aac0fafa12ba6a8e3ed8c121c6efc73e to your computer and use it in GitHub Desktop.
check weather and time conditions
#!/bin/bash
LOCATION="Hampshire"
CONDITION=`curl -s wttr.in/$LOCATION?format=%C`
SUNSET=`curl -s wttr.in/$LOCATION?format=%s`
SUNRISE=`curl -s wttr.in/$LOCATION?format=%S`
TIME=`date "+%H:%M:%S"`
sunset_time=$(date -d $SUNSET +%s)
sunrise_time=$(date -d $SUNRISE +%s)
current_time=$(date -d $TIME +%s)
CONDITIONS=('Sunny' 'Partly cloudy' 'Clear')
echo "Location: $LOCATION | Weather: $CONDITION"
echo "Time: $TIME | Sunrise: $SUNRISE | Sunset: $SUNSET"
if [[ ${CONDITIONS[*]} =~ $CONDITION ]]
then
#echo "Compatible weather condition"
if [ $current_time -ge $sunset_time ]
then
echo "It's not solar time, killing xmrig"
#pkill -9 xmrig
elif [ $current_time -ge $sunrise_time ]
then
echo "It's solar time, running xmrig"
bash check_xmrig.sh
fi
else
echo "Incompatible weather condition, killing xmrig"
#pkill -9 xmrig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment