Checking yum connectivity from a script?
Solution 1:
Here's one way to do it, the crux of it is the *Repo-baseurl:" which is reported by the yum repolist command:
# curl -s --dump-header - `yum repolist rhcd -v | grep Repo-baseurl | awk '{print $2}'` -o /dev/null
HTTP/1.1 200 OK
Date: Fri, 17 May 2013 09:58:30 GMT
Server: Apache/2.2.3 (CentOS)
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html;charset=ISO-8859-1
Breakdown of that:
yum repolist rhcd -v
Loading "fastestmirror" plugin
Config time: 0.104
Yum Version: 3.2.22
Loading mirror speeds from cached hostfile
Repo-id : rhcd
Repo-name : rhcd
Repo-status : enabled:
Repo-updated: Mon Nov 1 14:37:19 2010
Repo-pkgs : 2,599
Repo-size : 3.7 G
Repo-baseurl: http://lochost:81/core_build/il31/centos/5Server/i386/CentOS/
Extract the baseurl with grep and pipe to awk for the url.
use curl's dump header option to see the http status:
HTTP/1.1 200 OK
Date: Fri, 17 May 2013 09:58:30 GMT
Server: Apache/2.2.3 (CentOS)
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html;charset=ISO-8859-1
Of course yum is a really nicely put together python program so I guess you could also put it together as a python utility importing the relevant bits of yum.
Without a reponame yum repolist will list all of the yum repositories. You can then process them in a loop.
Solution 2:
For me, the following command worked:
yum repolist -v | grep Repo-baseurl | awk '{print $3}'
instead of this one:
yum repolist rhcd -v | grep Repo-baseurl | awk '{print $2}'
And for multiple yum-repos, you could do the following:
for repourl in $(yum repolist -v | grep Repo-baseurl | awk '{print $3}') ; do echo $repourl; curl -s --dump-header - $repourl -o /dev/null; done
Will result in:
http://repo-url-1/
HTTP/1.1 200 OK
Date: Sat, 31 Aug 2019 08:32:35 GMT
Server: Apache/2.2.15 (CentOS)
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html;charset=UTF-8
http://repo-url-2/
HTTP/1.1 200 OK
Date: Sat, 31 Aug 2019 08:32:36 GMT
Server: Apache/2.2.15 (CentOS)
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html;charset=UTF-8