ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Unsolved Redirecting feedback from Linux command

    IT Discussion
    linux bash scripting redirect
    2
    7
    884
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JaredBuschJ
      JaredBusch
      last edited by JaredBusch

      So, normal output is redirected to my log file.
      5c3b2b09-d280-47d2-8451-4ff615d0d6a4-image.png
      But this status bar that pops up on the bottom of the screen when you manually upgrade still shows on the screen.
      11139a2f-5e56-4b3d-af9b-6cd8ec5abec2-image.png

      As I am using a script to perform all of this, I would rather not see this.
      Said Script: https://gitlab.com/bundyassociates/freepbx-scripts/setup-scripts/-/blob/master/setup.sh

      How do I determine what output this status bar is?

      1 Reply Last reply Reply Quote 0
      • JaredBuschJ
        JaredBusch
        last edited by

        Trial and error led me to determine that it is stderr.

        That is annoying as hell. One would assume that actual errors I may want to see show up there also.

        I don't want that in the logfile or on my screen. but I do want actual errors.

        1 1 Reply Last reply Reply Quote 0
        • JaredBuschJ
          JaredBusch
          last edited by

          This makes it not show up anyplace.

          printf "Upgrading all installed modules...\n" | tee -a $logfile
          fwconsole ma upgradeall 2> /dev/null >> $logfile
          

          Redirecting 2, which is stderr, to /dev/null while appending the rest to the logfile >> $logfile.

          1 Reply Last reply Reply Quote 0
          • 1
            1337 @JaredBusch
            last edited by 1337

            @JaredBusch said in Redirecting feedback from Linux command:

            Trial and error led me to determine that it is stderr.

            That is annoying as hell. One would assume that actual errors I may want to see show up there also.

            I don't want that in the logfile or on my screen. but I do want actual errors.

            stderr is for both diagnostics and errors so I guess one could argue that it's diagnostics. Otherwise it's bad form for a developer to print anything to stderr that doesn't belong there.

            I suggest piping stderr to a file instead of /dev/null. Then you can examine the file. Determine what you don't want to end up in stderr. Then when you run fwconsole you can pipe stderr to grep and remove what you don't want.

            1 1 Reply Last reply Reply Quote 0
            • 1
              1337 @1337
              last edited by 1337

              @Pete-S said in Redirecting feedback from Linux command:

              Then when you run fwconsole you can pipe stderr to grep and remove what you don't want.

              Something like this should do the trick:

              fwconsole ma upgradeall 1>> $logfile2 2> >(grep -v what_you_don't_want >&2) 
              
              • stdout is appended to the $logfile2 with 1>> $logfile2
              • stderr is output with process substitution to grep with 2> >(grep bla bla bla) which then pipes it's output back to stderr with >&2
              JaredBuschJ 1 Reply Last reply Reply Quote 1
              • JaredBuschJ
                JaredBusch @1337
                last edited by JaredBusch

                @Pete-S Pretty much what I do not want is the status bar from these two commands.

                fwconsole ma upgradeall
                2f21ab0d-51fe-455e-95bb-4a9a94dfcb7e-image.png

                fwconsole chown
                092a99de-0b57-4f1e-87c1-a7cf68c7b44f-image.png

                1 1 Reply Last reply Reply Quote 0
                • 1
                  1337 @JaredBusch
                  last edited by 1337

                  @JaredBusch said in Redirecting feedback from Linux command:

                  @Pete-S Pretty much what I do not want is the status bar from these two commands.

                  fwconsole ma upgradeall

                  fwconsole chown

                  Well, use grep to match for the progress bar then.

                  First output stderr to a file and look in the file.

                  I don't know how the progress bar looks when it's output as a stream of characters.
                  I'm guessing every update is something like

                  3076094/3076094 [===========>-------------] 60%<CR>
                  

                  In that case grep for every line that doesn't contain a [ followed by a number of =, > or - and finally a ].

                  So something like:

                  grep -v  '[[=->]+\]'
                  

                  Or maybe even better:

                  grep -v  '[[=->]{28}\]'
                  

                  Above assuming there are always 28 characters inside the brackets in the progress bar.


                  PS.
                  Funny thing but there seems to be a bug in the forum software.
                  I had to use an extra backslash to get the above regex look right [[=->]+\\] instead of [[=->]+\]
                  They look right in the preview though.

                  1 Reply Last reply Reply Quote 1
                  • 1 / 1
                  • First post
                    Last post