1

I'm trying to add nVidia GPU utilization to my byobu-tmux status line. I've installed gpustat which returns

~$ gpustat
myhost                 Mon Aug 19 17:26:51 2019  410.48
[0] GeForce GTX 1080 Ti | 22'C,   0 % |     0 / 11178 MB |
[1] GeForce GTX 1080 Ti | 41'C,   0 % |     0 / 11175 MB |

then I wrote a text processor saved to ~/.byobu/bin/2_gpu as suggested in the byobu web page for custom status.

~$ cat .byobu/bin/2_gpu
#!/bin/sh
echo "$(gpustat | tail -n+1 | sed -nr "s/\[[0-9]\].+([0-9]+)\s\%.*$/\1%/p" | tr [:space:] ',' | head -c-1)" 

from the bash shell that seems to work; whether the shebang is sh or bash doesn't seem to matter, it works fine:

~$ .byobu/bin/2_gpu
0%,0%

however I can't get that text onto the byobu-tmux status line. A simpler custom status works fine, but there's some problem escaping the quotes and/or '$' in the regex argument to the sed command. I'm not sure why echo is even needed, but removing the echo "$(...)" doesn't help, nor does adding backslashes on the inner double-quote and '$' characters.

0

okay, after an immense amount of fiddling, this seems to do what I want, with the bonus of nice color-coding:

#!/bin/sh
SED_PATTERN='s/^.*([0-9]+)\s%.*$/\1%%,/p'
GPUSTAT="$(gpustat | tail -n+2 | sed -nr $SED_PATTERN | head -c-2)"
echo "#[bg=blue]GPU:$GPUSTAT#[bg=black]"
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.