0

I am tring to run the below code in python3 running on Centos8

namespace="abcnkabc51-admin-ns"
podtype="smd"
appPodName="smd-84b4bf8fcc"
cmd_appNodeNames="kubectl get pod --show-labels -o wide -n "+namespace+"|egrep \"app="+podtype+"\" |grep "+appPodName+"| awk \'{print $7}\'"
print("cmd_appNodeNames: ")
print(cmd_appNodeNames)

I am getting the printout like this-

cmd_appNodeNames: 
| awk '{print $7}'show-labels -o wide -n abcnkabc51-admin-ns|egrep "app=smd" |grep smd-84b4bf8fcc 

However, expected output would be as below-

cmd_appNodeNames: 
kubectl get pod --show-labels -o wide -n abcnkabc51-admin-ns|egrep "app=smd" |grep smd-84b4bf8fcc| awk '{print $7}'

Would you please advise how can I fix this?

Regards,

Ashish

Ashish
  • 27
  • 4

2 Answers2

0

I cannot reproduce this (on Ubuntu, but that makes no difference):

$ python3
Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> namespace="abcnkabc51-admin-ns"
>>> podtype="smd"
>>> appPodName="smd-84b4bf8fcc"
>>> cmd_appNodeNames="kubectl get pod --show-labels -o wide -n "+namespace+"|egrep \"app="+podtype+"\" |grep "+appPodName+"| awk \'{print $7}\'"
>>> print("cmd_appNodeNames: ")
cmd_appNodeNames: 
>>> print(cmd_appNodeNames)
kubectl get pod --show-labels -o wide -n abcnkabc51-admin-ns|egrep "app=smd" |grep smd-84b4bf8fcc| awk '{print $7}'
>>> 
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Hi, Thanks for checking. I have identified the issue. The actual program is a bit complex. appPodName was a output from a pxssh function; unfortunately this value contained \r at the end. After splitting \r, I have been able to fix this . – Ashish May 16 '22 at 02:20
0

The actual program is a bit complex. appPodName was an output from a pxssh function; unfortunately this value contained \r at the end. After splitting \r, I have been able to fix this.

Ashish
  • 27
  • 4