修复执行sed命令无效的问题

main
RogerWork 3 months ago
parent 25313c6d81
commit ae7d0897eb
  1. 29
      update/utils/cmd.py
  2. 7
      update/utils/cmd_extcute.py

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

@ -65,7 +65,8 @@ class UpdateCommandUtil:
exec_list = []
for exec_cmd in _exec_cmd_list:
print('执行命令对象:', exec_cmd)
stdin, stdout, stderr = self.client.exec_command(exec_cmd['cmd'])
cmd = str(exec_cmd['cmd']).replace(r'\\', '\\').replace(r"\'", "'")
stdin, stdout, stderr = self.client.exec_command(cmd)
out = stdout.read().decode('utf-8')
err = stderr.read().decode('utf-8')
print('正确输出:', out)
@ -100,6 +101,8 @@ class UpdateCommandUtil:
exec_cmd_data = self.get_checked_cmd(cmd_list, is_delete)
if _type == 'setup':
cmds = exec_cmd_data['sys'] + exec_cmd_data['setup']
elif _type == 'combo':
cmds = exec_cmd_data['setup']
elif _type == 'teardown':
cmds = exec_cmd_data['teardown']
else:
@ -141,7 +144,7 @@ class UpdateConfigUtil:
if cmds['combo_cmd'] != 0:
update_cmd = UpdateCommandUtil()
result, setup_output = update_cmd.exec_cmd_by_type(self.ip, 'setup', [cmds['combo_cmd']],
result, setup_output = update_cmd.exec_cmd_by_type(self.ip, 'combo', [cmds['combo_cmd']],
short_release, is_delete='1')
print('执行关联命令:', setup_output)

Loading…
Cancel
Save