Article 569DC Loop with case - feedback

Loop with case - feedback

by
orangepeel190
from LinuxQuestions.org on (#569DC)
Hi there!

I am trying to create a loop and inside the loop, I am wishing to have a case - that is triggered when certain website results are returned.

Code:sleep="12h"
for i in {1..5}; do
response=$(curl -Lso $file -z $file $url -w "%{http_code}")

case "$response" in
200)
echo "File $file found ..."
do something
exit
;;
301)
echo "Received: HTTP $response ==> $url\n"
do_something
sleep $sleep
# retry
;;
304)
echo "Received: HTTP $response ==> $url\n"
do something
sleep $sleep
# retry
;;
401)
echo "Received: HTTP $response ==> $url\n"
do something
sleep $sleep
# retry
;;
404)
echo "Received: HTTP $response ==> $url\n"
do something
sleep $sleep
# retry
;;
500)
echo "Received: HTTP $response ==> $url\n"
do something
sleep $sleep
# retry
;;
503)
echo "Received: HTTP $response ==> $url\n"
do something
sleep $sleep
# retry
;;
*) echo "Received: HTTP $response ==> $url\n"
do something
sleep $sleep
# retry
;;
esac
doneThe thought behind this script is to run at a certain day of the week, with pauses of 12 hours (hence the loop) to recheck the URL returns. The script will end with either the expiration of the loop or when the certain URL is returned and triggers an EXIT command.

I was hoping someone would cast their eyes over the code that I have written and make suggestions/improvement to it. I am having difficulties in getting it to loop back correctly....

I was thinking about an IF statement but there are simply too many and I think that a CASE option may be the best (cannot think of alternative).latest?d=yIl2AUoC8zA latest?i=1cZeFekMCBI:kg31-zuysro:F7zBnMy latest?i=1cZeFekMCBI:kg31-zuysro:V_sGLiP latest?d=qj6IDK7rITs latest?i=1cZeFekMCBI:kg31-zuysro:gIN9vFw1cZeFekMCBI
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments