Curl 입력에서 Bash 변수 값이 부분적으로 대체되었습니다.

Curl 입력에서 Bash 변수 값이 부분적으로 대체되었습니다.

다음은 변수 값 을 curl. v_sub_get패치 curl.

스크립트:

#!/bin/bash

PATH=/opt/SP/apps/jq/:/opt/SP/jboss/home/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
export PATH

function Create_Profile {

content=$(curl -X POST  -D /var/SP/data/monitoring/probes/create_profile_headers.txt -sS  https://somedomain/backend/profile/  -H 'accept: application/json'   -H 'content-type: application/json'  -d '{"user_details": {
                "name": "myname",
                "given_name": "Diego",
                "family_name": "Maradona",
                "middle_name": "Armando",
                "preferred_username": "pibe de oro",
                "nickname": "masterofuniverse",
                "profile": "http://www.god.com",
                "picture": "http://www.handsome.com/diego.gif",
                "website": "http://www.god.com",
                "email": "[email protected]",
                "email_verified": "true",
                "gender": "male",
                "zoneinfo": "CET",
                "locale": "AR",
                "phone_number": "493333333333",
                "phone_number_verified": true,
                "address": {
                    "street_address": "6767 Collins Ave",
                    "locality": "Miami Beach",
                    "region": "FL",
                    "postal_code": "33141",
                    "country": "DE"
                }
            },
            "device_details": {
                "user_agent": "iOS",
                "device_id": "123123123123123123",
                "ip_address": "1.2.3.4"
            },
            "security_details": {
                "password": "India@1234",
                                    "security_questions": [{
                        "question": "Who is God?",
                        "answer": "me"
                    }]
                }
            }')

v_sub_get=`echo $content | jq -r .user_details.sub`

echo "Sub value for Profile created: $v_sub_get"

http_response=`cat /var/SP/data/monitoring/probes/create_profile_headers.txt | awk -F " " '/HTTP\/1.1 / {print$2}'`
v_etag=`cat /var/SP/data/monitoring/probes/create_profile_headers.txt | awk -F " " '/ETag/ {print$2}'`


#echo "Create Profile invoked"

echo "ETag value: $v_etag"

http_response_create=`echo $http_response|awk {print$2}`

echo "http_response_create: $http_response_create"

dt=$(date '+%d/%m/%Y %H:%M:%S')

if [ "$http_response_create" == "100 201" ]
then echo "$dt  Success Create Profile is working Fine.  http_response_create: $http_response_create"  >> /var/SP/data/monitoring/probes/Probe_logs.txt
create_exit_code=0
else echo "$dt  Error   Create Profile has some Issue.  http_response_create: $http_response_create"  >> /var/SP/data/monitoring/probes/Probe_logs.txt
create_exit_code=2
fi


}

################ Update Profile for created user #####################

function Update_Profile {

#echo "Update Profile Invoked"

echo "Sub_value_patch: $v_sub_get"


patch_content=$(curl -X PATCH -D /var/SP/data/monitoring/probes/update_profile_headers.txt \
 -sS  "https://somedomain/backend/profile/${v_sub_get}" \
 -H  'content-type: application/merge-patch+json' \
 -H  "if-none-match: ${v_etag}" \
 -d  '{"user_details": {"name": "MyNewName"}}' )


http_response_update=`cat /var/SP/data/monitoring/probes/update_profile_headers.txt| awk '/HTTP/ {print $2}'`


echo "http_response_update: $http_response_update"

v_updated_name=`echo $patch_content | jq -r .user_details.name`

echo "Updated Name: $v_updated_name"

dt=$(date '+%d/%m/%Y %H:%M:%S')

if [ "$http_response_update" -eq 201 ] && [ "$v_updated_name" == "MyNewName" ]
then echo "$dt  Success Update Profile is working Fine.  http_response_update: $http_response_update"  >> /var/SP/data/monitoring/probes/Probe_logs.txt
update_exit_code=0
else echo "$dt  Error   Update Profile has some Issue.  http_response_update: $http_response_update"  >> /var/SP/data/monitoring/probes/Probe_logs.txt
update_exit_code=2
fi


#echo $patch_content | jq -r .user_details.name


}

############## Delete Profile for User created ####################

function Delete_Profile {

delete_content=$(curl -X DELETE  -D /var/SP/data/monitoring/probes/delete_profile_headers.txt  -sS https://somedomain/backend/profile/$v_sub_get )

delete_response=`cat /var/SP/data/monitoring/probes/delete_profile_headers.txt | awk -F " " '/HTTP/ {print$2}'`


echo "http_response_delete: $delete_response"

dt=$(date '+%d/%m/%Y %H:%M:%S')

if [ $delete_response -eq 200 ]
then
  echo "$dt     Success Delete profile is working fine.  http_response_delete: $delete_response" >> /var/SP/data/monitoring/probes/Probe_logs.txt
delete_exit_code=0
else
  echo "$dt     Error   Delete profile has some issue.  http_response_delete: $delete_response"  >> /var/SP/data/monitoring/probes/Probe_logs.txt
delete_exit_code=2

fi

}




############# Get Profile of User ###############

function Get_Profile {

get_content=$(curl -X GET -D /var/SP/data/monitoring/probes/get_profile_headers.txt -sS  'https://somedomain/backend/profile/lookup?qemail=probe.test20%40gmail.com&qstatus=active' -H 'accept: application/json'  -H 'content-type: application/json')

v_sub_get=`echo $get_content | jq -r '.items[].sub'`

echo $v_sub_get

dt=$(date '+%d/%m/%Y %H:%M:%S')

get_response=`cat /var/SP/data/monitoring/probes/get_profile_headers.txt | awk -F " " '/HTTP/ {print$2}'`


if [ $get_response -eq 200 ]
then

echo "http_response_get: $get_response"

echo "$dt       Success Get profile is working Fine.  http_response_get: $get_response" >> /var/SP/data/monitoring/probes/Probe_logs.txt


if [ -z "$v_sub_get" ]
then
      echo "User profile does not exists.Creating the user profile."

      Create_Profile
      Update_Profile
      Delete_Profile


else
      echo "User profile exists"

      Delete_Profile
      Create_Profile
      Update_Profile
      Delete_Profile

fi

else

echo "$dt       Error     Get profile has some issue.  http_response_get: $get_response" >> /var/SP/data/monitoring/probes/Probe_logs.txt

echo "http_response_get: $get_response"

exit 2

fi

}

v_sub_get=""

v_etag=""

create_exit_code=""

update_exit_code=""

delete_exit_code=""


Get_Profile

dt=$(date '+%d/%m/%Y %H:%M:%S')

if (( $create_exit_code == 0 && $update_exit_code == 0 && $delete_exit_code == 0 ))
then
echo "$dt       NV Probe        0"  >> /var/SP/data/monitoring/probes/CRM_Probe_exit_status.log
exit 0
else
echo "$dt       NV Probe        2"  >> /var/SP/data/monitoring/probes/CRM_Probe_exit_status.log
exit 2
fi

디버그 출력:

구성 파일을 업데이트하기 위한 호출의 디버그 출력 부분:

+ Update_Profile
+ echo 'Sub_value_patch: 2790ca3e-74ee-486a-b991-6bf2dd4c6afb'
Sub_value_patch: 2790ca3e-74ee-486a-b991-6bf2dd4c6afb
++ curl -X PATCH -D /var/SP/data/monitoring/probes/update_profile_headers.txt -sS https://somedomain/backend/profile/2790ca3e-74ee-486a-' -d '{"user_details": {"name": "MyNewName"}}'n/merge-patch+json' -H 'if-none-match: 605434da-8e87-4b66-8397-c452b106a23a
+ patch_content='<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>'
++ cat /var/SP/data/monitoring/probes/update_profile_headers.txt
++ awk '/HTTP/ {print $2}'
+ http_response_update=400
+ echo 'http_response_update: 400'
http_response_update: 400

디버그 출력에서 ​​변수 "v_sub_get"의 값이 Update_profile 함수에 사용된 PATCH 함수에 의해 Curl에 대한 입력으로 부분적으로 대체되었음을 알 수 있습니다.

Curl에 대한 입력으로 사용될 때 변수 "v_get_sub"의 값이 부분적으로 대체되는 이유는 무엇입니까?

관련 정보