ParallelSSH / parallel-ssh

Asynchronous parallel SSH client library.
https://parallel-ssh.org
GNU Lesser General Public License v2.1
1.2k stars 149 forks source link

interactive shell and display same as terminal #359

Closed lafrinte closed 2 years ago

lafrinte commented 2 years ago

help wanted issue.

i use paramiko to connect network device and send commands. for performance and stability reasons, i'm trying to use pssh instead of paramiko but face some trouble in output parsing. the exact same display as the device terminal will help me locate the problem. (for network device, command prompt contains resource info and command mode)

In [96]: ssh = paramiko.SSHClient()

In [97]: ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

In [98]: ssh.connect(hostname=ip, port=port, username=user, password=password)

In [99]: shell = ssh.invoke_shell()

In [100]: shell.send("ls -al\n")
Out[100]: 7

In [101]: shell.recv(65535)
Out[101]: b'Last login: Thu Aug 25 08:29:09 2022 from 172.17.0.3\r\r\n[test@73dc979760a2 ~]$ ls -al\r\ntotal 24\r\ndrwx------ 2 test test 4096 Aug 24 16:26 \x1b[0m\x1b[01;34m.\x1b[0m\r\ndrwxr-xr-x 1 root root 4096 Aug 24 15:04 \x1b[01;34m..\x1b[0m\r\n-rw------- 1 test test    5 Aug 24 16:26 .bash_history\r\n-rw-r--r-- 1 test test   18 Nov 24  2021 .bash_logout\r\n-rw-r--r-- 1 test test  193 Nov 24  2021 .bash_profile\r\n-rw-r--r-- 1 test test  231 Nov 24  2021 .bashrc\r\n[test@73dc979760a2 ~]$ '