Sujet : AI Written Bash Script
De : kubmw2ce (at) *nospam* duck.com (DrStevenStrange)
Groupes : comp.sys.raspberry-piDate : 12. Dec 2024, 13:43:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vjelp3$24q57$1@dont-email.me>
User-Agent : Mozilla/5.0 (Macintosh; Intel Mac OS X 15.2; rv:91.0) Gecko/20100101 Firefox/91.0 SeaMonkey/2.53.19
Ok - don't laugh
My coding skills are pitiful so I asked my resident Ai to write a bash script to call a webcam script (I did write this one) only between sunrise and sunset. it produced this and it works! My question is - how can I amend the script so it starts 30 minutes BEFORE sunrise and stops 30 Minutes after?
#!/bin/bash
# Set your latitude and longitude
LATITUDE="mine"
LONGITUDE="mine"
# Fetch sunrise and sunset times in UTC
SUN_TIMES=$(curl -s "
https://api.sunrise-sunset.org/json?lat=$LATITUDE&lng=$LONGITUDE&formatted=0")
SUNRISE=$(echo $SUN_TIMES | jq -r '.results.sunrise')
SUNSET=$(echo $SUN_TIMES | jq -r '.results.sunset')
# Convert sunrise and sunset times to seconds since epoch
SUNRISE_EPOCH=$(date -d "$SUNRISE" +%s)
SUNSET_EPOCH=$(date -d "$SUNSET" +%s)
CURRENT_EPOCH=$(date +%s)
# Check if the current time is between sunrise and sunset
if [ $CURRENT_EPOCH -ge $SUNRISE_EPOCH ] && [ $CURRENT_EPOCH -le $SUNSET_EPOCH ]; then
echo "It's between sunrise and sunset. Running the other script..."
# Call the other script
./webcam.sh # Replace with the path to your script
else
echo "It's not between sunrise and sunset."
fi