Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: zypper: parsing output to human-readable form

  1. #1
    Guenther Schwarz NNTP User

    Default zypper: parsing output to human-readable form

    For automatic backup in 10.3 I use a script that calls zypper (0.8.25)
    and mails me the output, like:

    zypper up | $MAILER "$SENDMAILTO"

    However, while working nicely on the command line zypper produces a
    whole load of **** when the output is piped or redirected:

    ....
    * Installing: timezone-2008c-0.1 [0%]* Installing:
    timezone-2008c-0.1 [100%]* Installing: timezone-2008c-0.1 [0%]*
    Installing: timezone-2008c-0.1 [50%]* Installing:
    timezone-2008c-0.1 [0%]* Installing: timezone-2008c-0.1 [0%]*
    Installing: timezone-2008c-0.1 [1%]* Installing: timezone-2008c-0.1
    ....

    Obviously a problem with this fancy and useless progress bar. With rug
    and smart my script works just fine. Is there an easy way around this? I
    want just simple output that tells me in a short email what has been
    updated. Very much in the spirit of cron-apt on deb-based systems.

    Guenther

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: zypper: parsing output to human-readable form

    Yeah I noticed this too, but haven't bothered to solve it. Does the -q option help? What about -t and just grep the messages at the end?

    Seems to be a bug of zypper, it should test if stdout is a terminal before outputing cursor codes.

  3. #3
    Guenther Schwarz NNTP User

    Default Re: zypper: parsing output to human-readable form

    ken yap wrote:
    > Yeah I noticed this too, but haven't bothered to solve it. Does the -q
    > option help? What about -t and just grep the messages at the end?


    The example I gave was with the --quiet option already. -t (output in
    xml format) seems to be more promising:

    zypper -t up | grep done
    or
    zypper -t up | grep message

    Still have to test which xml types appear on various tasks, for example:
    <progress id="read-installed-packages" type="done" name=""/>
    <message type="warning">Nothing to do.</message>

    > Seems to be a bug of zypper, it should test if stdout is a terminal
    > before outputing cursor codes.


    Indeed.

    Guenther

  4. #4
    Kevin Nathan NNTP User

    Default Re: zypper: parsing output to human-readable form

    On Wed, 25 Jun 2008 12:50:25 GMT
    Guenther Schwarz <strap@gmx.de> wrote:

    >Obviously a problem with this fancy and useless progress bar. With rug
    >and smart my script works just fine. Is there an easy way around this?
    >I want just simple output that tells me in a short email what has been
    >updated.


    I've not used this, yet, but could the '--terse' option be any help? If
    you send me an email with your script, I'd be glad to look it over, see
    what can be done with the extraneous output . . . :-)


    --
    Kevin Nathan (Arizona, USA)
    Linux is not a destination, it's a journey -- enjoy the trip!

    Linux 2.6.22.18-0.2-default
    10:45am up 3 days 13:02, 21 users, load average: 0.28, 0.39, 0.43


  5. #5
    Guenther Schwarz NNTP User

    Default Re: zypper: parsing output to human-readable form

    Kevin Nathan wrote:
    > On Wed, 25 Jun 2008 12:50:25 GMT
    > Guenther Schwarz <strap@gmx.de> wrote:
    >
    >> Obviously a problem with this fancy and useless progress bar. With rug
    >> and smart my script works just fine. Is there an easy way around this?
    >> I want just simple output that tells me in a short email what has been
    >> updated.

    >
    > I've not used this, yet, but could the '--terse' option be any help? If
    > you send me an email with your script, I'd be glad to look it over, see
    > what can be done with the extraneous output . . . :-)


    Yes I switched from --quiet to --terse (xml output) since my last post.
    This is what I'm testing right now (testing is cumbersome as one has to
    wait for new stuff arriving on the mirrors in order to see any effect of
    changes):

    # parsing terse ouput of zypper
    # cleaning and building repositories
    test -e $TMPFILE && grep "done" $TMPFILE | grep "Cleaning" >> $MAILFILE
    test -e $TMPFILE && grep "done" $TMPFILE | grep "Building" >> $MAILFILE
    # downloads
    test -e $TMPFILE && grep "Downloading: " $TMPFILE >> $MAILFILE
    # installations
    test -e $TMPFILE && grep "Install" $TMPFILE | grep "100" >> $MAILFILE
    # warnings
    test -e $TMPFILE && grep "warning" $TMPFILE >> $MAILFILE

    Note that 'grep "done"' gives a lot of empty lines of the form
    <progress id="download" type="done" name=""/>
    with the interesting stuff in the 'name' field missing. So I have to
    search for the 100 from 'value="100"' instead. But this does not work
    for all operations. The percentage might jump to strange values instead
    of going from 0 to 100.

    Guenther

  6. #6
    Guenther Schwarz NNTP User

    Default Re: zypper: parsing output to human-readable form

    Guenther Schwarz wrote:
    > Kevin Nathan wrote:
    >> On Wed, 25 Jun 2008 12:50:25 GMT
    >> Guenther Schwarz <strap@gmx.de> wrote:
    >>
    >>> Obviously a problem with this fancy and useless progress bar. With
    >>> rug and smart my script works just fine. Is there an easy way around
    >>> this?
    >>> I want just simple output that tells me in a short email what has
    >>> been updated.

    >>
    >> I've not used this, yet, but could the '--terse' option be any help? If
    >> you send me an email with your script, I'd be glad to look it over, see
    >> what can be done with the extraneous output . . . :-)

    >
    > Yes I switched from --quiet to --terse (xml output) since my last post.
    > This is what I'm testing right now (testing is cumbersome as one has to
    > wait for new stuff arriving on the mirrors in order to see any effect of
    > changes):
    >
    > # parsing terse ouput of zypper
    > # cleaning and building repositories
    > test -e $TMPFILE && grep "done" $TMPFILE | grep "Cleaning" >> $MAILFILE
    > test -e $TMPFILE && grep "done" $TMPFILE | grep "Building" >> $MAILFILE
    > # downloads
    > test -e $TMPFILE && grep "Downloading: " $TMPFILE >> $MAILFILE
    > # installations
    > test -e $TMPFILE && grep "Install" $TMPFILE | grep "100" >> $MAILFILE
    > # warnings
    > test -e $TMPFILE && grep "warning" $TMPFILE >> $MAILFILE
    >
    > Note that 'grep "done"' gives a lot of empty lines of the form
    > <progress id="download" type="done" name=""/>
    > with the interesting stuff in the 'name' field missing. So I have to
    > search for the 100 from 'value="100"' instead. But this does not work
    > for all operations. The percentage might jump to strange values instead
    > of going from 0 to 100.


    Now it looks much nicer already than without the --terse option:

    <progress id="48" type="done" name="Cleaning repository 'GWDG1' cache"/>
    <progress id="75" type="done" name="Cleaning repository 'Packman
    Repository' cache"/>
    <progress id="114" type="done" name="Cleaning repository 'GWDG4
    (Packman)' cache"/>
    <progress id="47" type="done" name="Building repository 'GWDG1' cache"/>
    <progress id="74" type="done" name="Building repository 'Packman
    Repository' cache"/>
    <progress id="113" type="done" name="Building repository 'GWDG4
    (Packman)' cache"/>
    Downloading: bind-libs-9.4.1.P1-12.2_12.4.i586.delta.rpm
    Downloading: bind-utils-9.4.1.P1-12.2_12.4.i586.delta.rpm
    <progress id="install-resolvable" type="percentage" value="100"
    name="Installing: bind-libs-9.4.1.P1-12.4"/>
    <progress id="install-resolvable" type="percentage" value="100"
    name="Installing: bind-libs-9.4.1.P1-12.4"/>
    <progress id="install-resolvable" type="percentage" value="100"
    name="Installing: bind-utils-9.4.1.P1-12.4"/>
    <progress id="install-resolvable" type="percentage" value="100"
    name="Installing: bind-utils-9.4.1.P1-12.4"/>

    Now I know at least what repositories are used and which packages are
    updated. Still need a list of possible error messages to look out for:
    update servers not reachable, requests for clicking on license
    agreements, problems with installations etc.

    Guenther

  7. #7
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: zypper: parsing output to human-readable form

    Well it's XML after all so why not pass it through an XML parser and extract the elements you want? Maybe there's a DTD somwhere.

  8. #8
    Marco Munderloh NNTP User

    Default Re: zypper: parsing output to human-readable form

    If you don't care about the amount of progress lines you can filter out
    the stupid special chars with this:

    zypper -n up | tr -d '\033' | sed 's/\[2K\r/\n/g'

  9. #9
    Guenther Schwarz NNTP User

    Default Re: zypper: parsing output to human-readable form

    Marco Munderloh wrote:
    > If you don't care about the amount of progress lines you can filter out
    > the stupid special chars with this:
    >
    > zypper -n up | tr -d '\033' | sed 's/\[2K\r/\n/g'


    Thanks, I always get confused with special characters.

    Gnther

  10. #10
    Guenther Schwarz NNTP User

    Default Re: zypper: parsing output to human-readable form

    ken yap wrote:
    > Well it's XML after all so why not pass it through an XML parser and
    > extract the elements you want? Maybe there's a DTD somwhere.


    Sure. But then why is such an utility not included in the package in the
    first place? Zenworks Management? Anyway, I try to keep my scripts as
    simple as ever possible. So I'm fine with some grep commands for the moment.

    Gnther

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •