I have the following Script File 'bored.sh'. This file recursively calls itself.
curl "https://www.boredapi.com/api/activity" >>./bored.json
sleep 1s
bash ./bored.sh
I realized that this is a bad approach as it creates several instances and runs many processes that uses the system resources and ultimately crashes the system.
How do I terminate/kill all the previous instances of the scripts after they are executed (series of API call and store those response to file) sequentially but make sure this script runs indefinitely as only one or few child process and create less stress to my system?
EDIT I need to get the data from the API and store it to a file 'bored.json' once in every second.
while true; do ./bored.sh; doneand while you're at it, add asleepin there too so it's not running all the time (unless that is your goal).