This code works as expected outside of AWK
password_cmd="kubectl get secrets -o jsonpath=\'{.data.ssl-store-password}\' -n $namespace $password_secret"
echo $password_cmd
password=eval $password_cmd
output:
kubectl get secrets -o jsonpath=\'{.data.ssl-store-password}\' -n aircourier secret-aircourier-mq-password
When using it inside AWK I'm having problems escaping the quotes
First try
password_cmd="kubectl get secrets -o jsonpath=\'\''{.data.ssl-store-password}\'\'' -n $namespace $password_secret";
Output
awk: cmd. line:9: warning: escape sequence `\'' treated as plain `''
Second try
password_cmd='\''kubectl get secrets -o jsonpath=\'\''{.data.ssl-store-password}\'\'' -n $namespace $password_secret'\'';
Output
awk: cmd. line:9: password_cmd='kubectl get secrets -o jsonpath=\'{.data.ssl-store-password}\' -n $namespace $password_secret';
awk: cmd. line:9: ^ invalid char ''' in expression
Full script so far
#!/bin/bash
kubectl get secrets --all-namespaces | grep jks > keystores.tmp
# create table headers in the file for manage engine
echo '<--table K8_jks_secrets starts-->' > table.out
echo 'Namespace , Secret Name, Expire Date, Days Remaining' >> table.out
# awk through each line in keystores.tmp that we created earier
awk '{
#print $1, ", " $2, ", ";
namespace=1;
jks_secret=2;
print $namespace, ", " $jks_secret, ", ";
$password_secret=substr($2,1,length($2)-3)"password";
print $password_secret
password_cmd='\"'kubectl get secrets -o jsonpath=\'\''{.data.ssl-store-password}\'\'' -n $namespace $password_secret'\"';
print $password_cmd ;
}' keystores.tmp >> table.out
echo '<--table K8_jks_secrets starts-->' >> table.out