当访问yum repos时出现问题(例如,如果未配置所需的代理),运行“yum update”之类的命令将等待很长时间尝试许多不同的镜像.有时这很好,但有时我宁愿快速检查是否可以访问yum repos.
这是一种方法,它的关键是* Repo-baseurl:“由yum repolist命令报告:
原文链接:https://www.f2er.com/centos/373469.html# 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
细分:
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/
使用grep和pipe提取baseurl以获取url的awk.
使用curl的dump header选项查看http状态:
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
当然,yum是一个非常好的拼凑python程序,所以我猜你也可以把它作为一个python实用程序一起导入yum的相关位.
如果没有重新命名,yum repolist将列出所有yum存储库.然后,您可以循环处理它们.