0

I am trying to run the following command from Windows machine in the openshift docker container running Linux

oc exec openjdk-app-1-l9nrx -i -t --server https://xxx.cloud.ibm.com:30450 \
    --token <token> -n dev-hg jcmd \
    $(ps -ef | grep java | grep -v grep | awk '{print $2}') GC.heap_dump \
    /tmp/heap1.hprof

It is trying to evaluate jcmd $(ps -ef | grep java | grep -v grep | awk '{print $2}') GC.heap_dump /tmp/heap1.hprof on local windows machine and I do not have linux commands. Also, I need the process ID of the application running in container and not my local.

Any quick help is appreciated.

SYN
  • 4,476
  • 1
  • 20
  • 22
himanshu_mps
  • 170
  • 12

2 Answers2

0

Try this:

oc exec -it openjdk-app-1-l9nrx --server https://xxx.cloud.ibm.com:30450 \
  --token <dont-share-your-token> -n dev-hg -- /bin/sh -c \
  "jcmd $(ps -ef | grep java | grep -v grep | awk '{print \$2}')"

Or even:

oc exec -it openjdk-app-1-l9nrx --server https://xxx.cloud.ibm.com:30450 \
  --token <dont-share-your-token> -n dev-hg -- /bin/sh -c \
  "jcmd $(ps -ef | awk '/java/{print \$2}')"
SYN
  • 4,476
  • 1
  • 20
  • 22
0

The problem is that the $( ) piece is being interpreted locally. Surrounding it in double quotes won't help, as that kind of syntax is interpreted inside double quotes.

You have to replace your double quotes by single quotes (so $( ) is not interpreted), and then compensate for the awk single quotes:

oc exec openjdk-app-1-l9nrx -i -t --server https://xxx.cloud.ibm.com:30450 --token TOKEN -n dev-hg 'jcmd $(ps -ef | grep java | grep -v grep | awk '\''{print $2}'\'') GC.heap_dump /tmp/heap1.hprof'

Please add the tags unix and shell to your question, as this is more of a UNIX question than an Openshift one.

Ruben Helsloot
  • 12,582
  • 6
  • 26
  • 49
caxcaxcoatl
  • 8,472
  • 1
  • 13
  • 21