Follow

Ok. Unix nerds. Tell me your most obscure, interesting, or downright weird abuse of pipes. Bonus points for using tee and named pipes. Please if possible give the whole command (redact file names if necessary).

I'm teaching some people about what you can do on the UNIX command line and I need more examples.

@quixoticgeek I don't have the code, but I know people used to create a live email footer with a named pipe called .footer or something that was fed using a 'quote of the day' program (probably just a script that fed from an array of quotes)
Who uses footers anymore in email?

@quixoticgeek not weird, but quite long
(it's a real example that I used later in a training)

cat access.log | cut -f1 -d' ' | sort | uniq -c | sort -r -g | egrep '[0-9][0-9] [0-9]' | cut -b 9-

find all ip addresses with at least ten requests on an apache httpd log

@tth @quixoticgeek

not quite useless, here it is a pedagogic mean to distinguish "pure" filters (reading on stdin), then allowing to replace with other form of inputs, typically zcat.

(compression is a later topic in the training)

@quixoticgeek

At work, our normal setup has a comm manager, which sends UDP packets to a data radio to be transmitted. In one instance, we needed one comm manager to send to two radios. Unable to configure the comm manager to send duplicate messages, we came up with this. It listens for UDP packets and sends any packets it receives to two different destinations.

socat - udp4-listen:$S_RX,bind=$S_IP,fork | tee >(socat - udp-sendto:$R1_IP:$R1_RX) | socat - udp-sendto:$R2_IP:$R2_RX

@quixoticgeek I perpetrated a small repository just to explain that, instead of implementing heavy web services or complex low-level network code, you'd better just read/write from/to named pipe files, and be done with it: github.com/nojhan/named-pipes-

#unix #shell #webservices

Sign in to participate in the conversation
(void *) social site

(void*)