I have a Proxmox Server and I tried to write a Python script to exec some command on them. I also have a vscode server that run on the Proxmox Server and in the vscode server the program work fine but when I'm trying the same code (copy paste) in the vscode that installed on my PC I get this error "'command' is not recognized as an internal or external command, operable program or batch file."
I connect to the Proxmox with netmiko and run the commands.
this code is the same on the vscode server and on my PC:
from netmiko import ConnectHandler
import re
import subprocess
linux = {
'device_type': 'linux',
'ip': '1.1.1.1',
'username': 'my_username',
'password': 'my_pass',
'port': 1111,
'verbose': True
}
connection = ConnectHandler(**linux)
output = connection.send_command('sudo pct list | tail -n +2')
pattern = "\d{3}"
getConID = re.findall(pattern , output)
print (getConID)
connection.disconnect()
for container in getConID:
execCommand = subprocess.getstatusoutput('sudo pct status ' + container)
print (execCommand[1])
With connection.send_command
, you use netmiko to execute the command in an SSH shell on the server, but the subprocess is executed directly on your machine running the script. So, you must also use netmiko to run the command on the server.