Save the process id of the script to a file when the script is run and remove the file when your script is finished running. If the file with the PID in exists, you can use that as a condition to send a signal to the process to reset the counter.
#Set the counter to 0 at start and reset the counter on receiving signal USR1
i=0
trap "i=0" USR1
#If script already running, send signal to the PID and exit
pid_file=/tmp/myscriptpid
if [[ -e $pid_file ]]
then
kill -s USR1 $(cat $pid_file)
exit 0
fi
#Otherwise capture the PID and save to file, clean up on exit
echo "$$" >$pid_file
trap 'rm -f "$pid_file"' EXIT
Then you'll want to run your command in the background and kill it once you're done:
#Run the command in the background
your_command &
your_command_pid=$!
#Increment $i once each second.
count() {
sleep 1
((i++))
}
#Note that $i is reset to 0 if the script receives the USR1 signal.
while (( $i < 600 ))
do
count
done
#Kill the running command once the counter is up to 600 seconds
kill "$your_command_pid"