import paramiko
import time
import asyncio
def line_buffered(f):
line_buf = ""
while not f.channel.exit_status_ready():
line_buf += f.read(1)
if line_buf.endswith('\n'):
yield line_buf
line_buf = ''
def sshExec(ipaddress,deviceUsername,devicePassword,sshPort,command): #finalDict
try:
print("Performing SSH Connection to the device")
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ipaddress, username=deviceUsername, password=devicePassword, port=sshPort, look_for_keys=False, allow_agent=False)
print("Channel established")
(stdin, stdout, stderr) = client.exec_command(command)
stdin.close()
for line in stdout.read().splitlines():
print(line)
client.close()
print("Channel is closed")
except Exception as e:
print(e)
def main():
start = time.time()
tasks = []
#tasks.append(asyncio.create_task(sshExec('ev3dev','robot','maker','22',"brickrun /home/robot/mouse/main.py")))
#await asyncio.gather(*tasks)
#end = time.time()
#print("The time of execution of above program is :", end-start)
#if __name__ == "__main__":
#asyncio.run(main())
sshExec('hostname','user','password','22',"command")