6

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

  • 1
  • cannot reproduce on centos 7 – sivann Apr 7 '16 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 '16 at 16:52
  • Does ssh -t machine 'yum list' solve the problem? – egmont Apr 7 '16 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. – RubyTuesdayDONO May 17 '18 at 20:00
2

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

# unbuffer yum repolist
2

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 
  • 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 '16 at 18:56
  • 1
    Slightly modified: yum list installed | tail -n +5 | xargs -n3 | column -t | less cleans off the crud for unregistered redhat systems. – EdwinW Dec 11 '18 at 2:13
  • @egmont I tried your idea, and it worked quite well. – EdwinW Dec 11 '18 at 2:18
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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