14

When I SSH to a machine with ssh machine and run yum list it outputs everything that's installed as expected, and importantly every item is on one line like so:

xz-devel.i386                                                                                                        4.999.9-0.3.beta.20091007git.el5                                                                  base            
xz-devel.x86_64                                                                                                      4.999.9-0.3.beta.20091007git.el5                                                                  base            
xz-libs.i386                                                                                                         4.999.9-0.3.beta.20091007git.el5                                                                  base            
xz-lzma-compat.x86_64                                                                                                4.999.9-0.3.beta.20091007git.el5                                                                  base            

But upon doing it remotely with ssh machine 'yum list' or even piping it to grep while on the server with yum list | grep xz -C 3 the output's lines are "truncated" and made much shorter, like so:

xz-devel.i386                              4.999.9-0.3.beta.20091007git.el5
                                                                       base     
xz-devel.x86_64                            4.999.9-0.3.beta.20091007git.el5
                                                                       base     
xz-libs.i386                               4.999.9-0.3.beta.20091007git.el5
                                                                       base     
xz-lzma-compat.x86_64                      4.999.9-0.3.beta.20091007git.el5
                                                                       base     

How can I make the size of the line not shrink like this? My end desire is to pipe this to tee and then do some processing on the outputted file for all my hosts via ansible.

It seems that this is occurring due to some sort of "virtual terminal" as part of the SSH/piping because I can get the same behavior if I shrink my terminal size where the lines break when running yum list. Thus I'd assume that the addition of the pipe somehow tells yum list that the width of the terminal is only X columns

6
  • 1
  • cannot reproduce on centos 7
    – sivann
    Apr 7, 2016 at 16:21
  • 1
    Note also that yum list does not list everything that is installed (it lists everything that is available). For a list of installed packages, you probably want rpm -qa, the output of which is much more suitable for scripting parsing. In particular, also see the documentation for the --queryformat option to the rpm command.
    – larsks
    Apr 7, 2016 at 16:52
  • Does ssh -t machine 'yum list' solve the problem?
    – egmont
    Apr 7, 2016 at 18:55
  • 1
    idk if this would solve in your specific situation, but often piping to cat is enough to tell a program that stdout isn't a tty, and therefore don't prettify output. w/ yum, for example, doing that will prevent right-justification of the trailing columns. May 17, 2018 at 20:00

5 Answers 5

9

Per this answer provided in the comments by @thrig I was able to get it to output correctly by doing

yum list installed | xargs -n3 | column -t 
3
  • I'd be curious to hear if my proposal (in a comment above) works for you; that'd be way simpler and catch the real cause why combining ssh and yum in a single step gives a different result than interactively logging in and executing yum remotely. I don't have a remote machine to test my theory.
    – egmont
    Apr 8, 2016 at 18:56
  • 2
    Slightly modified: yum list installed | tail -n +5 | xargs -n3 | column -t | less cleans off the crud for unregistered redhat systems.
    – EdwinW
    Dec 11, 2018 at 2:13
  • @egmont I tried your idea, and it worked quite well.
    – EdwinW
    Dec 11, 2018 at 2:18
4

Install expect, which comes with unbuffer(1), and run:

# unbuffer yum repolist
3

I fought with this today (during a yum check-update operation) and after finding a "CLOSED NOTABUG" bugzilla report and various python hacks, I came up with yet another workaround:

script -q -c "stty cols 150; yum check-update" /dev/null > /path/to/output.txt 2>&1

or:

script -q -c "stty cols 150; yum check-update" /path/to/output.txt > /dev/null

150 was an arbitrarily large-enough number to prevent wrapping; adjust that upwards if needed. The -q option inhibits the initial "Script started on $(date)" line, if you use a non-null output filename.

For the original problem, the line would be:

script -q -c "stty cols 150; yum list" /dev/null
3

None of the other answers worked for me on RHEL 7.7. So decided to use sed to concatenate next line to all lines that lack @ character.

yum list installed | sed '/^[^@]*$/{N;s/\n//}'
3

You can use the repoquery command to produce parsable output. For instance:

repoquery '*' --queryformat='%{name} %{evr} %{from_repo}' | column -t

gives:

0ad                0.0.23b-13.fc32  fedora
0ad                0.0.23b-17.fc32  updates
0ad-data           0.0.23b-4.fc32   fedora
0xFFFF             0.8-3.fc32       fedora
2048-cli           0.9.1-9.fc32     fedora
2048-cli-nocurses  0.9.1-9.fc32     fedora
2048-cli-sdl       0.9.1-9.fc32     fedora
2ping              4.3-6.fc32       fedora
2ping              4.5-1.fc32       updates
389-ds-base        1.4.3.18-1.fc32  updates

... and so on.

(Unlike dnf/yum, repoquery doesn't eliminate duplicate packages in its output)

2
  • 1
    When running on CentOS 7, I found that %{from_repo} didn't work. I had to use %{ui_from_repo} instead. Otherwise repoquery was exactly what I was looking for.
    – jgibson
    Dec 1, 2021 at 3:17
  • Thanks. I always forget when to use repoid/from_repo/ui_from_repo myself!
    – Sam Morris
    Dec 1, 2021 at 16:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .