解决执行

解决执行"yum-complete-transaction"命令时提示"except yum.Errors.RepoError, e:"错误问题

LM 412 2023-05-10

问题

更新Jenkins时系统卡住,就Ctrl+C强制取消了本次安装,但是yum的本次事务仍然存在,重新执行安装命令会显示以下内容

正在解决依赖关系
There are unfinished transactions remaining. You might consider running yum-complete-transaction, or "yum-complete-transaction --cleanup-only" and "yum history redo last", first to finish them. If those don't work you'll have to try removing/installing packages by hand (maybe package-cleanup can help).

按照提示执行yum-complete-transaction --cleanup-only会报以下错误

[root@localhost ~]# yum-complete-transaction --cleanup-only
  File "/usr/sbin/yum-complete-transaction", line 146
    except yum.Errors.RepoError, e:
                               ^
SyntaxError: invalid syntax

原因

yum-complete-transaction命令本质是一个python脚本,依赖python2,由于系统中存在python2python3,默认执行python命令会执行python3

[root@localhost ~]# python -V
Python 3.9.9

解决

修改yum-complete-transaction中的python依赖指向

[root@localhost ~]# vim /usr/sbin/yum-complete-transaction

#!/usr/bin/python -tt

................

import logging
import os
import os.path

#!/usr/bin/python -tt修改为#!/usr/bin/python2 -tt

保存后再次执行命令即可

[root@localhost ~]# yum-complete-transaction --cleanup-only
已加载插件:fastestmirror, product-id, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Loading mirror speeds from cached hostfile
Cleaning up unfinished transaction journals
Cleaning up 2023-05-10.11:18.25
[root@localhost ~]# yum history redo last
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Repeating transaction 36, from Wed May 10 11:38:50 2023
    安装 jenkins-2.332.3-1.1.noarch @jenkins
Loading mirror speeds from cached hostfile
软件包 jenkins-2.332.3-1.1.noarch 已安装并且是最新版本
history redo

参考

except yum.Errors.RepoError, e:_Doooooing的博客-CSDN博客