0

I have a multi line string variable defined in my shell script which alone I want to replace into a custom policy.xml file under specific session as per my condition passing the script. rest of the policy.xml variables need to be replaced with blank so that the custom policy generated will only have the condition passed values. I tried below script, but not able to achieve the xml content as i expected.

#!/bin/bash
######################variabes##############
IP_FILTER=$(cat <<EOF
        <rate-limit-by-key calls="${callThreshold}$"
            renewal-period="60"
            counter-key="@(Regex.Match(context.Request.Headers.GetValueOrDefault(&quot;X-Forwarded-For&quot;,&quot;&quot;), @&quot;^[.0-9]*&quot;)?.Value)" />

EOF)

source parse_yaml.sh
eval $(parse_yaml sample2.yaml policy)

for f in $policy_ ; do
  if [[ $(eval echo \$${f}_name) == "ipfilter" ]]; then
    echo " given policy name is ipfilter "
    for g in $(eval echo \$${f}_session_); do
      if [[ $(eval echo \$${g}) == "inbound" ]]; then
      echo "add the add above Ipfilter string to the inbound session of xml"
      ***cat policy.xml | sed -e 's/Search_IP_FILTER/$IP_FILTER/' >>*** result_$policy.xml
      fi
      if [[ $(eval echo \$${g}) == "outbound" ]]; then
      echo "add the add above Ipfilter string to the outbound 

sameway, i want to define multiple policy string variables and need to replace under specific session of the policy xml file.

I tried something like below, but the xml replacement is not working as expected.

  if [[ $(eval echo \$${g}) == "inbound" ]]; then
  echo "add the add above Ipfilter string to the inbound session of xml"
  ***cat policy.xml | sed -e 's/Search_IP_FILTER/$IP_FILTER/' >>*** result_$policy.xml

The policy.xml file looks below and want to replace only the variable which satisfies the session section and rest of the policy variables should be empty.

<policies>
    <inbound>
        <base />
         $(ip_filter)
         $(rate-limit-by_ip)
         $(rate-limit-by_subkey)
         $(rate-limit-by_DevID)
         $(rate-limit-by_ip)+$(rate-limit-by_DevID)
    </inbound>
    <backend>
        <base />
         $(ip_filter)
         $(rate-limit-by_ip)
         $(rate-limit-by_subkey)
         $(rate-limit-by_DevID)
         $(rate-limit-by_ip)+$(rate-limit-by_DevID)
    </backend>
    <outbound>
        <base />
         $(ip_filter)
         $(rate-limit-by_ip)
         $(rate-limit-by_subkey)
         $(rate-limit-by_DevID)
         $(rate-limit-by_ip)+$(rate-limit-by_DevID)
    </outbound>
    <on-error>
        <base />
         $(rate-limit-by-ip_error)
         $(rate-limit-by_DevID_error) 
    </on-error>
</policies>
2

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.