parent
25313c6d81
commit
ae7d0897eb
2 changed files with 34 additions and 2 deletions
@ -0,0 +1,29 @@ |
|||||||
|
import paramiko |
||||||
|
|
||||||
|
|
||||||
|
class UpdateCommandUtilDemo: |
||||||
|
def __init__(self): |
||||||
|
self.client = paramiko.SSHClient() |
||||||
|
self.channel = None |
||||||
|
|
||||||
|
def connect(self, cinema_ip): |
||||||
|
cinema_config = {'hostname': cinema_ip, 'port': 22, 'username': 'root', 'password': 'cine123456'} |
||||||
|
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
||||||
|
self.client.connect(**cinema_config) |
||||||
|
|
||||||
|
def disconnect(self): |
||||||
|
self.client.close() |
||||||
|
|
||||||
|
def exec_cmd(self, cinema_ip): |
||||||
|
self.connect(cinema_ip) |
||||||
|
cmd = "sed -i 's/dy.yinghezhong.com/zzcs.yinghezhong.com/g' /data1/cine/code/run/install/basic_data.sql" |
||||||
|
stdin, stdout, stderr = self.client.exec_command(cmd) |
||||||
|
print('stdin', stdin) |
||||||
|
print('stdout', stdout.read().decode('utf-8')) |
||||||
|
print('stderr', stderr.read().decode('utf-8')) |
||||||
|
self.disconnect() |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
cmd_obj = UpdateCommandUtilDemo() |
||||||
|
cmd_obj.exec_cmd('172.16.3.166') |
Loading…
Reference in new issue