I am using the bash script to connect to the mysql database and execute a query.
I use the below script to connect to the database and execute the query.
#!/bin/bash
Total_Results=$(mysql -h server-name -P 3306 -u username-ppassword -D dbname<<<"select URL from Experiment where URL_Exists = 1");
for URL in "$Total_Results";
do
echo $URL
var=$(curl -s --head $URL | head -n 1 | grep "HTTP/1.[01] [23]..")
echo "$var"
if [ -z "$var" ]
then
echo "Ok we do not have a valid link and the value needs to be updated as -1 here"
else
echo "we will update the value as 1 from here"
fi
done
The problem is the result set is considered as a one whole result and I am getting inside the else loop only once (we will update the value as 1 from here is printed only once). I have 2500 valid URLs and I expect 2500 echoes of we will update the value as 1 from here
.
How can I process each and every row as a single result from mySQL query?