Score:0

Loop to test HTTP Status Code?

ro flag

I have a script to test several internal URL (around 15-20 URL) from an external Server which looks like this(i changed the URL to some random url like youtube etc. for this post):

#!/bin/bash 
code=`curl -i -L -s "https://www.youtube.com/ https://www.google.com/ https://twitter.com/?lang=de| grep 200` 
if [ -z "$code" ]
then
exit 0 
else
exit 1
fi

I want to put all the URL in a Variable(if possible) and then for example do curl -i -L -s $ALLURL and grep for HTTP 200 or put them somehow in a list (i think there is something called "table" in Linux(idk?) so i can then do curl -i -L -s (all the URL´s).

If one of URL`s gets a HTTP 200 then it should exit with status code 1 (exit 1) and if not it should just do exit 0

Why do i want to change my script even tho it is working? Because it can be a bit confusing to remove or check if one URL is missing when they are all in one single Line.

i would like to have the URL like this in the script:

https://URL1 
https://URL2 
https://URL3
...

Thanks to anyone who can help me with this.

muru avatar
us flag
"Why do i want to change my script even tho it is working?" I don't see a working script here. The code you pasted certainly doesn't do what you want it to do ("If one of URLs gets a HTTP 200 then it should exit with status code 1 (exit 1) and if not it should just do exit 0")
Artur Meinild avatar
vn flag
For everyone starting on Bash scripting, I'll recommend [this online course](https://www.youtube.com/playlist?list=PLT98CRl2KxKGj-VKtApD8-zCqSaN2mD4w) to get you started.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.