LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-10-2021, 02:58 AM   #1
rihad
LQ Newbie
 
Registered: Sep 2021
Posts: 8

Rep: Reputation: Disabled
Shell pipeline q'n


Hi. This command writes a status line every 5 seconds:

Code:
$ zpool iostat -n -q 5
              capacity     operations     bandwidth    syncq_read    syncq_write   asyncq_read  asyncq_write   scrubq_read   trimq_write
pool        alloc   free   read  write   read  write   pend  activ   pend  activ   pend  activ   pend  activ   pend  activ   pend  activ
----------  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----
zroot        167G   473G    398    209  17.8M  5.14M      0      0      0      0      0      0      0      0      0      0      0      0
zroot        167G   473G      0     42  19.3K   281K      0      0      0      0      0      0      0      0      0      0      0      0
^C
I'm not interested in the pool name, capacity, scrub and trim operations, so I decide to use colrm to get rid of them. First the left hand side:


Code:
$ zpool iostat -n -q 5 | colrm 1 26
 operations     bandwidth    syncq_read    syncq_write   asyncq_read  asyncq_write   scrubq_read   trimq_write
 read  write   read  write   pend  activ   pend  activ   pend  activ   pend  activ   pend  activ   pend  activ
-----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----
  398    209  17.8M  5.14M      0      0      0      0      0      0      0      0      0      0      0      0
^C
So far so good. Now for the right hand side:

Code:
$ zpool iostat -n -q 5 | colrm 1 26 | colrm 85
This doesn't output anything and hangs until Ctrl+C is pressed!

I should note that it doesn't matter what the last command is, even cat -u, even head -n1 - it will hang. But if the "feeder" is killed, the expected output is delivered:

Code:
$ timeout 15 zpool iostat -n -q 5 | colrm 1 26 | colrm 85
 operations     bandwidth    syncq_read    syncq_write   asyncq_read  asyncq_write  
 read  write   read  write   pend  activ   pend  activ   pend  activ   pend  activ  
-----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  
  398    209  17.8M  5.14M      0      0      0      0      0      0      0      0  
    0     33      0   214K      0      0      0      0      0      0      0      0  
    0      0      0      0      0      0      0      0      0      0      0      0
What the $#$% is going on? Thanks for any advice.


P.S.: this doesn't hang, so it must be something in colrm (and cut -b):

Code:
$ zpool iostat -n -q 5 | cat | cat

Last edited by rihad; 10-10-2021 at 03:05 AM. Reason: p.s.
 
Old 10-10-2021, 03:32 AM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,334

Rep: Reputation: Disabled
This is a very common problem. The output from the command is being buffered. If you wait for a while, a sudden rush of output will appear when the buffer is full (which is clearly not what you want).

Try running the zpool command via stdbuf or unbuffer, like this:
Code:
stdbuf --output=L zpool iostat -n -q 5 | colrm 1 26

unbuffer -p zpool iostat -n -q 5 | colrm 1 26
I'm sure you can find other ways of doing it by Googling something like "forcing line buffering in pipes".
 
1 members found this post helpful.
Old 10-10-2021, 04:07 AM   #3
rihad
LQ Newbie
 
Registered: Sep 2021
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Ser Olmy View Post
This is a very common problem. The output from the command is being buffered. If you wait for a while, a sudden rush of output will appear when the buffer is full (which is clearly not what you want).

Try running the zpool command via stdbuf or unbuffer, like this:
Code:
stdbuf --output=L zpool iostat -n -q 5 | colrm 1 26

unbuffer -p zpool iostat -n -q 5 | colrm 1 26
I'm sure you can find other ways of doing it by Googling something like "forcing line buffering in pipes".
Damn! You're right! Thanks a lot! It was colrm doing the buffering. This helped:

zpool iostat -n -q 5 | stdbuf -o L colrm 1 26 | colrm 85


Code:
$ zpool iostat -n -q 5 | stdbuf -o L colrm 1 26 | colrm 85
 operations     bandwidth    syncq_read    syncq_write   asyncq_read  asyncq_write  
 read  write   read  write   pend  activ   pend  activ   pend  activ   pend  activ  
-----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  
  396    208  17.7M  5.12M      0      0      0      0      0      0      0      0  
    0      0      0      0      0      0      0      0      0      0      0      0  
^C
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell test if argument passed by pipeline is a file gigiux Linux - Newbie 5 04-30-2019 01:37 AM
LXer: pv (Pipe Viewer) - Shell pipeline element to meter data passing through LXer Syndicated Linux News 0 12-28-2008 09:20 PM
Having a tough time with K-shell pipeline pjz Programming 4 03-24-2005 03:05 PM
pipeline using rm verstapp Linux - General 3 03-08-2004 11:33 PM
Pipeline implementation in C jiahe Programming 1 02-02-2003 05:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration