Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Limit on number of pipes after long-running command?


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Limit on number of pipes after long-running command? [SOLVED]

I'm trying to create a minimal, crude keylogger for X using only a shell script. I was quickly stumped: Why do these two commands entered in a terminal emulator produce output when I type...

Code:
$ xinput test 6 | grep press

Code:
$ xinput test 6 | awk '{print $3}'

...but this command produces no output:
Code:
$ xinput test 6 | grep press | awk '{print $3}'

?

This observation is really challenging my understanding of stdout, stdin, and pipes.

BTW, 6 is the id of my keyboard, which I found by running xinput list. My shell is bash version 5.0.3

Last edited by DevuanFan; 05-16-2019 at 01:10 PM..
# 2  
grep filters lines and shows only lines which contain "press" (case sensitive).

What's the output of xinput test 6 in all cases?
# 4  
Here is the output in the terminal when I type unix after executing the command:

Code:
$ xinput test 6
key press   30 
key release 30 
key press   57 
key release 57 
key press   31 
key release 31 
key press   53 
key release 53

This is the output I want (you'd think this would be the output of the third command in my original post when, in fact, that command outputs nothing):
Code:
30
57
31
53

--- Post updated at 03:00 PM ---

@nezabudka: The command you suggested generates no output, either.
# 5  
I don't know what you mean by 6 is the id of my keyboard, which I found by running xinput list, but how about:
Code:
xinput test 6 6>&1 | awk '/press/ {print $3}'

# 6  
@vgersh99: X input devices have id's, which vary from machine to machine (on my machine, X sees the keyboard as input id=6 and mouse as input id=7, for instance).

Yes, the command you suggested gives the desired output when I type unix:
Code:
$ xinput test 6 | awk '/press/ {print $3}'
30
57
31
53

But it still leaves unanswered why we can only use one pipe after xinput test 6. For instance, this command produces no output when I type unix, although I'd expect grep to generate some ouput when u is pressed:
Code:
$ xinput test 6 | awk '/press/ {print $3}' | grep 30

What I'm trying to understand is why one pipe after xinput test 6 works fine, but two pipes never produce any output even when output is expected. That's the point of the thread.

Last edited by DevuanFan; 05-16-2019 at 12:20 PM..
# 7  
Quote:
Originally Posted by DevuanFan
@vgersh: Yes, the command you suggested gives the desired output when I type unix:
Code:
$ xinput test 6 | awk '/press/ {print $3}'
30
57
31
53

But it still leaves unanswered why we can only use one pipe after xinput test 6. For instance, this command produces no output when I type unix, although I'd expect grep to generate some ouput when u is pressed:
Code:
$ xinput test 6 | awk '/press/ {print $3}' | grep 30

What I'm trying to understand is why one pipe after xinput test 6 works fine, but two pipes never produce any output even when output is expected.
well, it's not the "number" of pipes, but the output redirection of xinput:
Code:
xinput test 6 6>&1 | awk '/press/ {print $3}'

seems that xinput test 6 put its output not to stdout stream, but to stream with fileDescriptor 6, but the following awk reads its input from stdin (where stdin has the fd=1).
Hence, we need to map fd=6 of xinput to fd=1: 6>&1 for the awk to read its input from fd=1
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
How to put a 80 character limit on a long topic line in markdown?
dragonpoint
I have a topic line in markdown that spans more than 80 characters that i need to add a line break. Markdown is simply treating the line break as a brand new line instead of continuing as a topic line. Eg: # This is a very long line Markdown interprets it as This is a very long line... UNIX for Beginners Questions & Answers
4
UNIX for Beginners Questions & Answers
Limit process number in TOP command outupt
vikram3.r
Linux top command prints more than 40 processes. top -b -n 1 > Top_Output.txt Is there a straight-forward option/way to limit only till the top 5 processes. ( Instead of using head, tail or other unix commands together)... UNIX for Dummies Questions & Answers
1
UNIX for Dummies Questions & Answers
Limit on Number of Cron Jobs Running on one Account
Pramodini Rode
Hello, I have some 150 Cron Jobs running under my UNIX account. I want to add some more jobs. Is there a limit to the number of cron jobs that can be run on an account? Thank you. Pramodini... UNIX for Advanced & Expert Users
8
UNIX for Advanced & Expert Users
Number of long limit
herath
Hi Hi! I'm currently using AIX 5.2 and would like to know where can i find to see that there's a restriction on the number of login times a user can have. Example, I want give a 2 login per user but some one to give 3 login and some one have to give unlit login time (without logging off the...... UNIX for Dummies Questions & Answers
2
UNIX for Dummies Questions & Answers
How to limit the number of running instances of a script?
oti
I would like to allow only one instance of a script to run at any moment. I've tried the following solution to count the instances but the result is always the number of running instances plus one and I can't find the problem ps -ef | grep $0 | sed '/^$/ d' | sed '/grep/ d' | wc -l Please...... Shell Programming and Scripting
2
Shell Programming and Scripting

Featured Tech Videos