AI Written Bash Script

Dec 12, 2024 Last reply: 1 year ago 5 Replies

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 "

formatting link
$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


[...]

Since you already have the date/time in seconds since the epoch, just subtract 30 seconds for BEFORE and add 30 seconds for AFTER

Josef

[...]

Since you already have the date/times in seconds since the epoch, just add/subtract 30 minutes worth of seconds for AFTER and BEFORE!

Josef

How about

SUNRISE_EPOCH=$(($(date -d "$SUNRISE" +%s) - 1800)) SUNSET_EPOCH=$(($(date -d "$SUNSET" +%s) + 1800))

Why not just ask the AI goonbot to do that?

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required