尝试在mongo上运行脚本,以检查用户获取错误:无法执行二进制文件,任何建议。
[bp09@zlv172 ~]$ sh disk.sh
./kubectl config use-context agef
./kubectl exec -it mongoagef-2 -c mongo bash -- df -h
/usr/bin/df: /usr/bin/df: cannot execute binary file
command terminated with exit code 126当被试时:
./kubectl exec -it mongoagef-2 -c mongo bash -- file /usr/bin/df bash: file:没有以退出代码127终止的文件或目录命令。
./kubectl config use-context agef
./kubectl exec -it mongoagef-2 -c mongo bash -- df -h
/usr/bin/df: /usr/bin/df: cannot execute binary file
command terminated with exit code 126
[bp09@zlv172 ~]$ ./kubectl config use-context agef
Switched to context "agef".
[bp09@zlv172 ~]$ ./kubectl get pods
NAME READY STATUS RESTARTS AGE
mongoagef-0 2/2 Running 0 20d
mongoagef-1 2/2 Running 0 24d
mongoagef-2 2/2 Running 0 20d
[bp09@zlv172 ~]$ ./kubectl exec -it mongoagef-2 -c mongo bash
bash-4.2$ df -h /data/db
Filesystem Size Used Avail Use% Mounted on
/de/map/data_vg-shared_vol2 3.5T 1.8T 501G 75% /data/db但当你跟:-
[bp09@zlv172 ~]$ ./kubectl exec -it mongoagef-2 -c mongo bash -- df -h
/usr/bin/df: /usr/bin/df: cannot execute binary file
command terminated with exit code 126
[bp09@zlv172 ~]$ ./kubectl exec -it mongoagef-2 -c mongo bash -- file /usr/bin/df -h
bash: file: No such file or directory
command terminated with exit code 127
[bp09@zlv172 ~]$ ./kubectl exec -it mongoagef-2 -c mongo bash -- file /bin/df -h
bash: file: No such file or directory
command terminated with exit code 127下面的命令是:- df 09@zlv172 172 ~$ locate df。
/bin/df
[bp09@zlv172 ~]$ ./kubectl exec -it mongoagef-2 -c mongo bashbash-4.2美元cd /usr/bin bash-4.2美元ls -lrth|grep -i df
-rwxr-xr-x 1 root root 99K Oct 30 2018 df发布于 2021-05-06 14:18:29
正如您所提到的,当登录到容器并运行命令时,df命令是有效的,但在使用exec运行时则不起作用。或者,您可以调用shell,然后调用所需的命令。例:
kubectl exec -it mongo -c mongo -- /bin/sh -c df如果存在
-c选项,则从第一个非选项参数command_string读取命令。如果在com- mand_string之后有参数,则第一个参数分配给$0,其余的参数都分配给位置参数。$0的赋值设置shell的名称,该名称用于警告和错误消息。
发布于 2021-05-06 08:59:00
-it mongo -c mongo - /bin/sh -c df -这个功能很好。
https://stackoverflow.com/questions/67305590
复制相似问题