Skip to content

Instantly share code, notes, and snippets.

@h3ct0r
Created July 2, 2021 17:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h3ct0r/7361d50c3ed889558124983434f2c3c6 to your computer and use it in GitHub Desktop.
Save h3ct0r/7361d50c3ed889558124983434f2c3c6 to your computer and use it in GitHub Desktop.
Query GPU usage (with nvdia-smi) on a list of servers via SSH. It ask for password for all machines and store it on a variable which is cleared after the script is finished (no password is kept in the bash logs).
read -p "User please: " -s USER && read -p "Password please: " -s PASS && echo -e "\nBeginning SSH query with user: $USER\n" && for host in '150.164.212.21' '150.164.212.23' '150.164.212.24' '150.164.212.25' '150.164.212.26' '150.164.212.27' '150.164.212.28' '150.164.212.33' '150.164.212.36' '150.164.212.37' '150.164.212.40' '150.164.212.42' '150.164.212.43' '150.164.212.45' '150.164.212.71' '150.164.212.72' '150.164.212.73' '150.164.212.75' '150.164.212.76' '150.164.212.80' '150.164.212.81' '150.164.212.117' '150.164.212.141' '150.164.212.148' '150.164.212.164' '150.164.212.171' '150.164.212.204' '150.164.212.226'; do sshpass -p $PASS ssh -oStrictHostKeyChecking=no $USER@$host 'echo "host:$(hostname) GPU usage: $(nvidia-smi --query-gpu=utilization.gpu,memory.free,memory.total --format=csv,noheader)"' 2> /dev/null; done && PASS="" && USER=""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment