When there is a problem with access to yum repos (for example if a needed proxy isn't configured), running a command like 'yum update' will wait for a very long time trying lots of different mirrors. Sometimes that is good, but sometimes I would rather check quickly whether access to yum repos is OK.
Is there a way to get yum to quickly check its connectivity and give me a status code indicating whether access to remote repos is OK?
Here's one way to do it, the crux of it is the *Repo-baseurl:" which is reported by the yum repolist command:
Breakdown of that:
Extract the baseurl with grep and pipe to awk for the url.
use curl's dump header option to see the http status:
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.
For me, the following command worked:
instead of this one:
And for multiple yum-repos, you could do the following:
Will result in:
I had the same need (check if proxy is configured correctly), and while the above solutions gave hints, none was a complete solution, as checking with curl does not use the http proxy configured in yum.
Firstly, yum proxy can be configured:
per-repo by adding
proxy=http://<proxy_ip>:<proxy_port>
in each/etc/yum.repos.d/*.repo
globally, by adding
proxy=http://<ip>:<port>
andhttp_caching=none
in yum.conf (no caching to avoid getting stale repmod.xml causing checksum mismatches)1. First, get a list of repositories and URLs:
2. Clear yum cache to avoid cached answers
Then for each repository in repolist.csv, do the following:
3a. query repo contents with yum (about 15 seconds for base)
3b. alternatively query a specific package with repoquery (about 7 seconds for base)
I don't think there is a general command to check yum connectivity. What you can do is this: create a test repo in
/etc/yum.repos.d/test.repo
that just checks against a single location instead of the whole mirrors list so things are more speedy.and then give a yum command in the form
if you get a connection error chances are that your internet connectivity is at fault. Of course centos.org could also be down in the above example but the chances of that are slimmer.