1 回答
TA贡献1860条经验 获得超9个赞
类型的corev1.PodExecOptions.Command接受值[]string。
req.VersionedParams(&_v1.PodExecOptions{
Stdin: false,
Stdout: true,
Stderr: true,
TTY: false,
Container: containerName,
Command: cmds,
}, parameterCodec)
其中,cmds可以是:
cmds := []string{
"sh",
"-c",
"echo $HOME; ls -l && echo hello",
}
输出:
/root
total 68
drwxr-xr-x 2 root root 4096 Feb 24 00:00 bin
drwxr-xr-x 2 root root 4096 Feb 1 17:09 boot
drwxr-xr-x 2 root root 4096 Feb 24 00:00 mnt
drwxr-xr-x 2 root root 4096 Feb 24 00:00 opt
dr-xr-xr-x 396 root root 0 Mar 19 11:47 proc
drwx------ 2 root root 4096 Feb 24 00:00 root
.
.
hello
说明: 蒂姆的回答
command: ["/bin/sh","-c"]
args: ["command one; command two && command three"]
该命令["/bin/sh", "-c"]说“运行一个外壳,并执行以下指令”。然后将 args 作为命令传递给 shell。在 shell 脚本中,asemicolon分隔命令,&&如果第一个成功,则有条件地运行以下命令。在上面的例子中,它总是在 commandone之后运行 command two,并且只有在threecommandtwo成功时才运行 command 。
注意: 对于 bash,它将类似于以下内容:
cmds := []string{
"bash",
"-c",
`export MYSQL_PWD=${MYSQL_ROOT_PASSWORD}
mysql -h localhost -nsLNE -e "select 1;" 2>/dev/null | grep -v "*"`,
},
- 1 回答
- 0 关注
- 548 浏览
添加回答
举报
