Skip to content

Instantly share code, notes, and snippets.

@jpsutton
Created September 5, 2023 20:34
Show Gist options
  • Save jpsutton/8734ce209f7874d5e386d2865c1adc8a to your computer and use it in GitHub Desktop.
Save jpsutton/8734ce209f7874d5e386d2865c1adc8a to your computer and use it in GitHub Desktop.
Reading an Nvidia GPU temperature value from a libvirt Windows guest
#!/bin/bash
GUEST_NAME=Win10_With_GPU
job_exited="false"
exec_result=$(virsh -c qemu:///system qemu-agent-command "$GUEST_NAME" '{"execute": "guest-exec", "arguments": { "path": "nvidia-smi.exe", "arg": [ "--format=csv,noheader", "--query-gpu=temperature.gpu" ], "capture-output": true }}')
exec_pid=$(echo "$exec_result" | jq ".return.pid")
while [ "$job_exited" == "false" ]; do
exec_job_data=$(virsh -c qemu:///system qemu-agent-command "$GUEST_NAME" '{"execute": "guest-exec-status", "arguments": { "pid": '" ${exec_pid}}}")
job_exited=$(echo "$exec_job_data" | jq '.return.exited')
if [ "$job_exited" == "false" ]; then
sleep .1s
continue
fi
echo "$exec_job_data" | jq '.return["out-data"]' | tr -d '"' | base64 --decode
break
done
@pallaswept
Copy link

It's the thought that counts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment