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 關注
- 485 瀏覽
添加回答
舉報