Skip to content
Advertisement

How can I use the watch command with a customized nvidia-smi output message?

I use the nvidia-smi command quite frequently, and I have a separate alias in my .bashrc that I use to monitor it (alias gpu='watch -n 3 nvidia-smi').

I recently learned about customizing the output message of nvidia-smi and am using the following: nvidia-smi | tee /dev/stderr | awk '/ C / {print $3}' | xargs -r ps -up that I got from this Stack Overflow question.

I’d like to replace the original nvidia-smi command in my watch alias, but am wondering how I can do so. Simply replacing it doesn’t work, and I’ve tried surrounding the new command in quotation marks but that leads to the original nvidia-smi message along with a

error: user name does not exist

Usage:
 ps [options]

 Try 'ps --help <simple|list|output|threads|misc|all>'
  or 'ps --help <s|l|o|t|m|a>'
 for additional help text.

For more details see ps(1).

right below it.

How should I go about achieving what I want? Any help is appreciated. Thanks.

Advertisement

Answer

Try this to see if it produces expected result :

alias gpu='watch -n 1 "nvidia-smi | tee /dev/stderr | awk '"'"'/ C / {print $3}'"'"' | xargs -r ps -up"'

'"'"' is to escape single quote inside single quotes.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement