0

maybe some of you openshift/docker pros can help me out with this one. Apologies in advance for my formatting, im on mobile and dont have access to exact error codes right now. I can supply more detailed input/stderr later if needed.

Some details about the environment:

-functioning OC pod running a single postgresql v9.6 container.

-CentOS7 host

-Centos7 local machine

-bash 4.2 shell (both in the container and on my local box)

My goal is to use a one-liner bash command to rsh into a postgresql container, and run the following command to print said containers databases to my local terminal. something like this:

[root@mybox ~]$ oc rsh pod-name /path/to/command/executable/psql -l

result: rsh cannot find required library, error code 126

The issue I am hitting is that, when executing this one liner, The rsh does not see the target pod’s environment variables. This means it cannot find the supporting libraries that the psql command needs. If i dont supply the full path as shown in my example, it cannot even find the psql command itself.

Annoyingly, running the following one liner prints all of the pods environment variables (including the ones i need for psql) to my local terminal, so they should be accessible somehow.

[root@mybox ~]$ oc rsh pod-name env

Since this is to be executed as part of an automated procedure, the simple, interactive rsh approach (which works, as described below) is not an option.

[root@mybox ~]$ oc rsh pod-name

sh-4.2$ psql -l

(pod happily prints the database info in the remote terminal)

I have tried executing the script which defines the psql environment variable and then chaining the desired command, but i get permission denied when trying to execute the env script.

[root@mybox ~]$ oc rsh pod-name /path/to/env/define/script && psql -l

permission denied, rsh error code 127

  • Have you tried `oc exec`? That's typically meant for automated one-liners. – Will Gordon Jun 11 '19 at 10:33
  • 1
    The application being run should see all that `env` saw. The issue is more likely that there is special activation occurring to set additional environment variables when a bash shell environment is being created. Try something like `oc rsh pod-name bash -c "/path/to/command/executable/psql -l"`. – Graham Dumpleton Jun 11 '19 at 11:25
  • @Will Gordon I have tried oc exec, and hit the same issues. – David Ross Jun 11 '19 at 12:42
  • @Graham Dumpleton that worked! I knew it would be something relatively simple like this. one strange thing that i noticed was that this does not work when passing —shell=‘/bin/bash’ as an argument to oc rsh. but starting a bash shell explicitly with oc rsh pod-name bash as you reccomended does indeed do the job. – David Ross Jun 11 '19 at 13:29
  • The ``--shell`` argument only applies when run ``oc rsh pod-name`` with no command to run. That will run the specified or default shell in the pod leaving you with a prompt. – Graham Dumpleton Jun 12 '19 at 23:11

0 Answers0