Skip to content

Commit 40dc862

Browse files
committed
add encoding and close channel
1 parent a6bdea1 commit 40dc862

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

py2022/ssh_cmd.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/python
2+
# *_* coding=utf-8 *_*
23

34
import paramiko
45

@@ -28,6 +29,7 @@ def exec_cmd(cmd):
2829
print('connecting: %s' % h)
2930
client.connect(h, port=port, username=username, password=password,
3031
timeout=5)
32+
# 多次执行命令 可复用同一个Channel
3133
chan = client.get_transport().open_session()
3234
print('exec cmd: %s' % cmd)
3335
chan.exec_command(cmd)
@@ -43,6 +45,7 @@ def exec_cmd(cmd):
4345
except Exception as e:
4446
print(e)
4547
finally:
48+
chan.close()
4649
client.close()
4750

4851

0 commit comments

Comments
 (0)