Sunday, September 4, 2022

[SOLVED] I want to execute the command with multiple argument on ssh using python

Issue

What I tried is to execute :

host=xyz
port = 22
username = xyz_username
ssh_cli = paramiko.SSHClient()
ssh_cli.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_cli.connect(host, port, username, allow_agent=False, timeout=None)

commands = [./BinaryExecutableFile  ./scene00021.bin ./scene00021.json  ./param.txt   ./cluster.json    ./count.json]
                        
for command in commands:
    ssh.client.exec_command(command)
    time.sleep(0.5)

terms

  • Binary file:BinaryExecutableFile
  • input file:./scene00021.bin output
  • output_file:./scene00021.apk
  • paramaters file1: ./param.txt
  • paramaters file2:./cluster.json
  • paramaters file3: ./count.json

Solution

You don't need a loop. There's just one command with multiple arguments. Concatenate them together to make the command line, and execute that.

ssh.client.exec_command(' '.join(commands))


Answered By - Barmar
Answer Checked By - Cary Denson (WPSolving Admin)