#!/usr/bin/env bash
exec 3>&1
fun_1(){
urlcount=$(wc -l < list.txt)
loopcount=0
for url in $(cat list.txt);
do
((loopcount++))
echo -e "\nProcessing URL #${loopcount} (of ${urlcount}) [ ${url} ]\n"
#the below curl command is the problem which i need to time it to maximum 5 minuts the continue the loop (because sometime it could take massive time to complete)
curl -s "http://localhost:5555/?url=$url"
# check for api status percentage
until [[ $(curl -s "http://localhost:5555/view/status" | jq -r '.status') == "100" ]]
do
echo -e "\n[-] Waiting for command $url\n"
sleep 5 || break
done
curl -s "http://localhost:5555/results" | jq -r '.results[]' >> results.txt
done
}
for domain in "$@"
do
fun_1 $domain 2>&1 >&3 | tee -a $WORKING_DIR/error_log.txt
done
This script has multiple functions like fun_1
which is execute one after another.
The problem is some functions which have a loop function using for
loop or while
loop could be running for very long time,
which is exhausting my server (VPS) and of course waste of time.
THE QUESTION is can I time this function to run for a certain time like one or two hour as maximum?