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
CodePudding user response:
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}'
>>>
CodePudding user response:
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.