Sooo, I am trying to log my ethminer hashrate, however I am having some troubles to chain the output of a egrep / grep into another one, I even tried with different commands (sed/cat...) none seems to actually get any sort of output, I can't even redirect stdout to a file! The weird part; when I don't try to chain or redirect anything, it prints what it is supposed to on the terminal!
after about 2h of research, I'm still on the same error (probably mine, but I can't really figure it out) and even after copying some stuff i found, I'm still in the same place...
here is the command i would like to filter:
/home/USER/ethminer -U -S eu1.ethermine.org:4444 -O 0x*****************.********** --cuda-parallel-hash 4
output this (it outputs about a bit more than a line/sec, and this needs to run basically forever):
ℹ 23:36:26|CUDA0 set work; seed: #4be89018, target: #0000000112e0
ℹ 23:36:26|CUDA0 set work; seed: #4be89018, target: #0000000112e0
m 23:36:28|ethminer Speed 20.01 Mh/s gpu/0 20.01 [A0+0:R0+0:F0] Time: 00:00
m 23:36:30|ethminer Speed 22.13 Mh/s gpu/0 22.13 [A0+0:R0+0:F0] Time: 00:00
The thing which interest me is the part after Speed, though there are hidden characters, here is what a chained
cat -e
displays:
^[[32m m ^[[35m23:38:10^[[0m^[[30m|^[[34methminer^[[0m Speed ^[[1;36m 23.09^[[0m Mh/s gpu/0 ^[[36m23.09^[[0m [A0+0:R0+0:F0] Time: 00:00^[[0m$
note the "Speed ^[[1;36m 23.09", I am using the 'm' as a reference to find the hashrate in the expression with m [[:digit:]]+\.[[:digit:]]{2}
(btw you'll see that I need to redirect the stderr into the stdout, this is because ethminer seems to output the hashrate in the stderr channel... kinda weird...)
This give me:
/home/USER/ethminer -U -S eu1.ethermine.org:4444 -O 0x*****************.********** --cuda-parallel-hash 4 2>&1 | cat -e | egrep -o --color=never "m [[:digit:]]+\.[[:digit:]]{2}" | egrep -o [[:digit:]]+\.[[:digit:]]{2}$
this output me what it is supposed to do:
m 0.00
m 15.74
m 19.41
So up to now, It's all OK... but after this one... everything is getting weird... I havn't managed to get any output... not even on my terminal from any chained command, I tried many things, from playing with redirection of stderr and stdout about everywhere, tried cat: no output, played a bit with sed: no luck, with grep: not any more chance than with sed... Idealy I would like something like this:
/home/USER/ethminer -U -S eu1.ethermine.org:4444 -O 0x*****************.********** --cuda-parallel-hash 4 2>&1 | cat -e | egrep -o --color=never "m [[:digit:]]+\.[[:digit:]]{2}" | egrep -o [[:digit:]]+\.[[:digit:]]{2}$ >> /home/USER/mining.log
Which would output:
22.26
22.47
in the mining.log file...
Help!
EDIT: ethminer is coming from here : https://github.com/ethereum-mining/ethminer this is the version 0.12.0
UDATE: The answer of egmont ended up working, if I understand correctly this is because of the way the data sent through pipes is buffered with ethminer... here is the command I ended up using:
stdbuf -oL ethminer [arguments] 2>&1 | stdbuf -oL cat -e | stdbuf -oL egrep -o "m [0-9]+\.[0-9]{2}" | stdbuf -oL egrep -o "[0-9]+\.[0-9]{2}" >> mining.log
cat -e
and just use something likegrep -Po 'Speed\s+\K[0-9.]+'
ethminer
isn't smart enough to turn off color codes when it's piped?grep Speed | sed ...
returned this :22.32 Mh/s gpu/0 22.32 [A0+0:R0+0:F0] Time: 00:01
so I might be able to make it work