0

I've trying to run the following script to check the available GPUs, however it doesn't run for two commands. If I run the command together it runs properly but not separately. I need to run separately as I have multiple GPUs and need to loop over them. Please tell me what am I doing wrong. I have tried many different approaches.

result= subprocess.run&(["ssh {}{}".format(user,server),"nvidia-smi"],shell=True)

When I run it says ssh is not recognized as an internal or external command.

MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
A.beer
  • 1
  • 3
  • do you have installed ssh ? – Druta Ruslan Jun 21 '18 at 16:36
  • The "correct" answer to this is probably to use `multiprocessing`. Create a process pool and assign each task to a new process. – ti7 Jun 21 '18 at 16:41
  • @zimdero yes I have it installed. When I run it like result=subprocess.run(["ssh user@hostname nvidia-smi"],shell=True) it runs perfectly but as soon i split it up and use multiple commands it gives that error – A.beer Jun 21 '18 at 16:57
  • @ti7 ahh. Okay. I'll give that a try too. I was just hoping there was a fix to this one as all the documentation and stack overflow mentioned this – A.beer Jun 21 '18 at 16:59
  • Sorry, I misunderstood your question. Take a look at [Paramiko](https://stackoverflow.com/questions/3586106/perform-commands-over-ssh-with-python) – ti7 Jun 21 '18 at 17:43
  • `subprocess.run()` takes either a single string (with `shell=True`), or a list of parameters (with `shell=False`). Generally speaking, `shell=False` is the better choice, but you do have to split the command into individual parameters - you can't put the `ssh` command and the user/server into a single parameter, they have to be separate list items. – jasonharper Jun 21 '18 at 20:02
  • @jasonharper thank you. I tried what you suggester and replaced it with subprocess.run([“ssh”,user,server,”nvidia-smi”],shell=False) but now i’m getting the error ‘ssh could not resolve hostname. If i run the same command as one line instead of splitting it up as a list i get proper list. I’m guessing there is something wrong with how it is written as a list? – A.beer Jun 22 '18 at 07:17
  • It looks like your user and server are supposed to be a single parameter (although I'm not sure where that `@` is coming from). – jasonharper Jun 22 '18 at 12:26
  • @jasonharper yes you were right about server and id being a single parameter. It works now. Thank you – A.beer Jun 25 '18 at 08:54

0 Answers0