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')