[英]Run remote command with Javascript
I want to run an awk command for a file in remote server. 我想为远程服务器中的文件运行awk命令。 I connect with ssh and I run the following command: 我连接ssh并运行以下命令:
cat /orch/servers | grep "+sNo+" | awk '{print $1}'
Type of this command's output is string. 该命令输出的类型是字符串。 But I want to this output be array. 但我想此输出为数组。 The javascript code is below: javascript代码如下:
vmIDListCmd = "cat /orch/servers | grep "+sNo+" | awk '{print $1}'"
try {
session = new SSHSession(hostName, username, 22);
session.connectWithPasswordOrIdentity(passwordAuthentication, password);
vmIDList = session.executeCommand(vmIDListCmd, true);
}
catch (e) {
throw "Unable to execute command: " + e;
}
finally {
if (session) {
session.disconnect();
}
System.log(vmIDList);
}
Output: 输出:
vm1 vm2 vm3 vm4
vmIDList variable (the output) is a string. vmIDList变量(输出)是一个字符串。 I want to this variable be an array. 我想这个变量是一个数组。
使用split
可以很容易地将字符串转换为数组。
var newArray = vmIDList.split(" ");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.