I’m working on a posix script (Linux) that fetches a webpage, stores the content in a variable and looks for the string “SUCCESS”. If the string found, content of the loop should not be executed, if the string is not found, then the loop should be executed over and over again until it is. I am trying to make all the curl and grep stuff happen in the control statement of the while loop, but I am not sure if it is possible at all, so far no succes:
while [ -z "site_status=`curl http://www.example.com/index.html | grep -o 'SUCCESS'`" ];
do
if [ `echo "$site_status" | grep -o 'WAIT'` ]; then
sleep 10s
elif [ `echo "$site_status" | grep -o 'RETRY'` ]; then
sleep 10s
else
exit 1
done
I want the script to be as clean as possible, so I try to avoid creating a function that saves the webpage content in a global variable and use this variable in the while loop.
Any suggestions on how to make the above while loop work? or maybe a better clean solution?
This one seems to do everything you’re asking for for me: