如何在bash变量中使用'kubectl cp'

时间:2019-05-22 19:48:05

标签: bash shell kubernetes grep kubectl

我试图使用shell脚本自动从kubernetes pod中复制文件。使用shell变量时出现意外错误。

我可以使用以下代码填充shell变量

➜  ~ read -r namespace pod other < <(kubectl get pods -o wide --all-namespaces | grep control- )
➜  ~ echo $namespace
mynamespace
➜  ~ echo $pod
control-7dbdb8fff8-8c548
➜  ~ read -r file other < <(kubectl exec -it $pod -n=$namespace -c my-sidecar -- ls | grep control)
➜  ~ echo $file
control-7dbdb8fff8-8c548_20190522_192354.dat

当我尝试将这些变量组合成kubectl cp命令时,我会收到错误消息

➜  ~ kubectl cp $namespace/$pod:$file -c my-sidecar ~/
: No such file or directory48_20190522_192354.dat
tar: error exit delayed from previous errors
 no such file or directory8c548_20190522_192354.dat

0 个答案:

没有答案