基于:
https://unix.stackexchange.com/questions/1459/remote-for-loop-over-ssh
我正在尝试通过oc rsh
运行for循环命令,但是失败,并出现以下错误:
$ oc rsh my-app-10-lprki 'for i in /var/lib/*; do echo $i; done'
exec failed: container_linux.go:345: starting container process caused "exec: \"for i in /var/lib/*; do echo $i; done\": stat for i in /var/lib/*; do echo $i; done: no such file or directory"
command terminated with exit code 1
我也尝试了不带引号,带双引号的操作,但这也失败了。
这很好(不带引号):
$ oc rsh my-app-10-lprki ls -la /var/lib/
total 24
drwxr-xr-x. 1 root root 104 Nov 22 22:21 .
drwxr-xr-x. 1 root root 17 Sep 28 2017 ..
drwxr-xr-x. 2 root root 44 Sep 28 2017 alternatives
关于如何通过oc rsh
远程运行for循环的任何建议,例如(当前失败):
oc rsh my-app-10-lprki 'for i in /var/lib/*; do echo $i; done'
?
基于以下建议,我也尝试过:
$ oc rsh my-app-10-lprki -- /bin/sh -c 'for i in `ls /var/lib`; do echo $i; done'
exec failed: container_linux.go:345: starting container process caused "exec: \"--\": executable file not found in $PATH"
command terminated with exit code 1
和:
$ oc rsh my-app-10-lprki -- /bin/bash -c 'for i in `ls /var/lib`; do echo $i; done'
exec failed: container_linux.go:345: starting container process caused "exec: \"--\": executable file not found in $PATH"
command terminated with exit code 1
和:
$ oc rsh my-app-10-lprki -- /usr/bin/bash -c 'for i in `ls /var/lib`; do echo $i; done'
exec failed: container_linux.go:345: starting container process caused "exec: \"--\": executable file not found in $PATH"
command terminated with exit code 1
位置:
$ oc rsh my-app-10-lprki which bash
/usr/bin/bash
答案 0 :(得分:1)
这可以解决问题:
oc exec my-app-10-lprki -- bash -c 'for i in /var/lib/; do echo $i; done'
答案 1 :(得分:0)
假设/bin/sh
外壳位于您的容器中
oc rsh my-app-10-lprki -- /bin/sh -c 'for i in `ls /var/lib`; do echo $i; done'
将列出/var/lib
目录中的文件
这是 mysql pod
的示例[suresh.vishnoi@blah ~]$ oc exec mysql-4-lnlpx -- /bin/sh -c 'for i in `ls /var/lib`; do echo $i; done'
alternatives
dbus
games
initramfs
machines
misc
mysql
rhsm
rpm
rpm-state
selinux
systemd
yum