我正在尝试使用以下命令获取应用程序版本
#!/bin/sh
appVersion=$(ssh username@server find '/dir1/dir2/dir3' -type f -name "file.json" -exec grep "version" {} \;| awk -F ': ' '{print $2}' | sed 's/\"//g')
echo $appVersion
不幸的是我得到了以下异常 find:缺少`-exec'的参数
请帮我解决此问题。
答案 0 :(得分:0)
运行以下脚本,该脚本将按预期运行。 当您通过ssh运行命令时,您应该使用单引号来执行多个命令
// This section all works fine. Establish SSH and expect Last Login info
ssh_cmd = ssh_cmd = "ssh " + self.user + "@" + self.hostname
self.proc = pexpect.spawn(ssh_cmd)
self.proc.expect("Last login", timeout = 5)
print("SSH login successful!")
self.is_connected = True
// Problems are here. Outside scope executes a command now by calling this:
// Let's say the command here is Sleep 5. Or an executable ./application
//The Pexpect below SHOULD wait until it finishes executing, but it
doesn't Sleep for 5 seconds or wait for ./application, this expect
line returns IMMEDIATELY every time.
def execute_command(self, command):
if self._is_connected:
self.proc.sendline("command")
self.proc.expect("username:/")