Files
SDK_SG200x_V2/cviruntime/scripts/evb/ssh_tool.py
carbon e25f20f7a3 add cviruntime
commit 3f4938648950a7f3bf9a19c320ca9fae7c52de20
Author: sophgo-forum-service <forum_service@sophgo.com>
Date:   Mon May 13 13:44:23 2024 +0800

    [feat] cviruntime opensource for cv18xx soc.

    - a4b6a3, add cumsum and gatherelements_pt.
2024-05-31 11:51:34 +08:00

52 lines
1.9 KiB
Python
Executable File

#!/usr/bin/python3
import argparse
import sys
import paramiko
class SshTool:
def __init__(self, host, user='root', password='cvitek'):
self.host = host
self.user = user
self.password = password
self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.__connect()
def __connect(self, try_cnt=5):
for i in range(try_cnt):
try:
self.ssh.connect(self.host, '22', self.user, self.password, timeout=20)
return
except Exception as e:
print(e)
continue
raise Exception("connection failed")
def exec(self, command):
_, stdout, stderr = self.ssh.exec_command(command)
for line in stdout.readlines():
print(line.strip())
for line in stderr.readlines():
print(line.strip())
err = stdout.channel.recv_exit_status()
print("ret:{}".format(err))
return err
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="SSH client")
parser.add_argument("-b", "--target", type=str, required=True,
help="specify ip of the target board")
parser.add_argument("-u", "--user", type=str, default="root",
help="specify the user name to login")
parser.add_argument("-p", "--password", type=str, default="cvitek",
help="password to login")
parser.add_argument("-t", "--timeout", type=int, default=0,
help="timeout time to connect")
parser.add_argument("-e", "--exec", type=str,
help="shell command to be executed on target board")
args = parser.parse_args()
ssh = SshTool(host=args.target, user=args.user, password=args.password)
ret = ssh.exec(args.exec)
sys.exit(ret)