Trying to run the script on mongo db to check utlization getting error: cannot execute binary file, any suggestions.
[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
When tried with:
./kubectl exec -it mongoagef-2 -c mongo bash -- file /usr/bin/df
bash: file: No such file or directory command terminated with exit code 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
but when running with : -
[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
when checked with locate df command below is the output:- bp09@zlv172 ~$ locate df
/bin/df
[bp09@zlv172 ~]$ ./kubectl exec -it mongoagef-2 -c mongo bash
bash-4.2$ cd /usr/bin bash-4.2$ ls -lrth|grep -i df
-rwxr-xr-x 1 root root 99K Oct 30 2018 df
k exec -it mongo -c mongo -- /bin/sh -c df this works fine.
As you mentioned that, df
command was working when you login to container and run the command, but not when run using exec
. Alternatively you Call the shell and then call the command you need. Eg:
kubectl exec -it mongo -c mongo -- /bin/sh -c df
-c If the -c option is present, then commands are read from the first non-option argument command_string. If there are arguments after the com‐ mand_string, the first argument is assigned to $0 and any remaining arguments are assigned to the positional parameters. The assignment to $0 sets the name of the shell, which is used in warning and error messages.