This is a sister question to my other question on a similar topic: I have a few commands, part of a larger script, that looks like this (one of many iterations):
stty -F /dev/ttyUSB0 115200 -echo raw -icrnl iutf8
cat /dev/ttyUSB0 | tee /dev/tty | grep --max-count=1 -F "root@ramfs:"
The intent here is that when an embedded device, connected via RS232 serial-USB cable, finishes booting, it will output the prompt that I am grepping for, and grep
will find that prompt and continue in script execution. I am not sure what is going wrong however, as when I can see that target string printed to my terminal, the command continues and grep
does not find a match. Some sample output is below (from various tries with different grep
and stty
options):
[[55;100R[ 9.177532] macb ff0c0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control tx
[ 9.185137] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
root@ramfs:~#
[[55;100Rroot@ramfs:~# [ 18.393491] macb ff0c0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control tx
[ 18.401103] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
root@ramfs:~# [ 18.393491] macb ff0c0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control tx
^[[55;100R
[[55;100Rroot@ramfs:~# [ 19.417479] macb ff0c0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control tx
[ 19.425087] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
root@ramfs:~# [ 19.417479] macb ff0c0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control tx
^[[55;100R
I can understand how the first example would not generate a match, as the target string only appears on the last line, and it would seem that grep will not operate on raw data from what I gather in other questions, meaning that another newline would be needed to generate a match. I do not understand, however, why the next two examples do not generate a match, as the target strings clearly appear within their own line, followed by a newline.
I am hoping someone can point out what I am doing wrong here/why it does not work like I would expect (I would expect at least the 2 and 3 examples would work), or suggest a more appropriate alternative that does not require so much coercion in this case. I would also be open to tips on troubleshooting this, as I am not really sure where I would start (printing everything as raw hex bytes is my first thought, but that does not seem like an efficient way to go about it).
=====================================================================
Edit:
Below is the output of cat /dev/ttyUSB0 > serialdump
followed by cat -TEv serialdump
^M^M$
^[7^[[r^[[999;999H^[[6nroot@ramfs:~# [ 17.401463] macb ff0c0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control tx^M$
[ 17.409067] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready^M$
And matching with cat serialdump -TEv | grep root@ramfs
$ cat serialdump -TEv | grep root@ramfs
^[7^[[r^[[999;999H^[[6nroot@ramfs:~# [ 17.401463] macb ff0c0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control tx^M