Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment

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.

[test]
name= test
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
enabled = 0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

and then give a yum command in the form

yum --disablerepo=* --enablerepo=test list available

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.