Another note to myself before I forget about this nifty usage
of socat again.
I was looking for something to mock a serial device, similar to
a microcontroller which usually ends up as /dev/ttyACM0
and might
output some text. What I found is a very helpful post on
stackoverflow
showing an example utilizing socat.
$ socat -d -d pty,rawer pty,rawer
2020/12/20 21:37:53 socat[29130] N PTY is /dev/pts/8
2020/12/20 21:37:53 socat[29130] N PTY is /dev/pts/11
2020/12/20 21:37:53 socat[29130] N starting data transfer loop with FDs [5,5] and [7,7]
Write whatever you need to the second pty, here /dev/pts/11
, e.g.
$ i=0; while :; do echo "foo: ${i}" > /dev/pts/11; let i++; sleep 5; done
Now you can listen with whatever you like, e.g. some tool you work on, on the fist pty,
here /dev/pts/8
. For demonstration purpose just use cat
:
$ cat /dev/pts/8
foo: 0
foo: 1
socat is an awesome tool, looking through the manpage you need some knowledge about sockets, but it's incredibly vesatile.