I want to use oc exec
to execute a cat
in my pod. In this cat
command I need to expand some variable.
cat /opt/amq/data/split-$index/running
So, I try this:
oc exec -i $pod -- '"/bin/bash" -s <<EOF cat /opt/amq/data/split-$index/running EOF'
But I cannot get it working.
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:235: starting container process caused "exec: \"\\\"/bin/bash\\\" -s <<-EOF cat /opt/amq/data/split-$index/running EOF\": stat \"/bin/bash\" -s <<-EOF cat /opt/amq/data/split-$index/running EOF: no such file or directory"
I can put cat and bash in separate lines, but the error is the same: $index
not expanded.
oc exec -i $pod -- '"/bin/bash" -c <<EOF
cat /opt/amq/data/split-$index/running
EOF'
Error:
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:235: starting container process caused "exec: \"\\\"/bin/bash\\\" -c <<EOF\\n cat /opt/amq/data/split-$index/running\\n EOF\": stat \"/bin/bash\" -c <<EOF\n cat /opt/amq/data/split-$index/running\n EOF: no such file or directory"
Find a way without using heredoc.
oc rsh
can run commands and return results directly:So that's what I need. Then I don't need
oc exec
.And, see the error message, it says:
Notice the
stat
, it seems to be looking for a file.