2

I'm trying to save the output of a command into files and it seems to work fine. However, when opening one of the files, I can see that output was limited to 80 characters width. How can I ensure that the output is not being wrapped? I've tried to put a tput rmam; at the beginning of the shell script but it doesn't seem to change the output behavior.

Script:

#!/usr/bin/env bash
CPUS=$(cat /proc/cpuinfo | grep "processor" | wc -l)
ansible-doc -l | cut -d " " -f1 > modules.txt
parallel --tmpdir src/yaml-snippets --files -a modules.txt -j$CPUS  ansible-doc -s {}

Example output:

- name: Module to manage datacenter quotas in oVirt/RHV
  ovirt_quota:
      auth:                  # (required) Dictionary with values needed to
                               create HTTP/HTTPS
                               connection to
                               oVirt: `username'
                               [`required'] -
                               The name of the
                               user, something
                               like
                               `admin@internal'.
                               Default value is
                               set by
                               `OVIRT_USERNAME'
                               environment
                               variable. `passwo
  • Is GNU parallel involved here? Does the wrapped formatting come from the ansible-doc -l command, or from the parallel'd ansible-doc -s command? Can you reproduce it without GNU parallel? – Jeff Schaller Apr 10 '19 at 01:57
  • Given that yum uses python, I'd be curious if this hack/workaround also works for ansible-doc. – Jeff Schaller Apr 10 '19 at 02:04
  • The actual output is generated by ansible-doc -s ovirt_quota. However, executing it plain on the shell and executing it through parallel have different output size. – memoryleak Apr 10 '19 at 12:34
  • Using the referenced hack worked @JeffSchaller : script -q -c "stty cols 1000; ansible-doc -s $1 > src/yaml-snippets/$1.yml" this line is called by cat modules.txt | xargs -t -n 1 -P$CPUS $DIR/generate.sh – memoryleak Apr 11 '19 at 19:31
  • Please feel free to self-answer, since I can't test in a similar environment to yours. Thanks! – Jeff Schaller Apr 11 '19 at 19:40
  • Just to point this out, parallel will figure out how many CPUs there are and run that many jobs in parallel with no -j flag, or if you want to explicitly say it, -j100% (which is the default).

    Also grep has a -c flag to count the number of matches, so grep -c "processor" /proc/cpuinfo will give you a count of the number of processors.

    – Larry Jun 29 '19 at 21:08

0 Answers0