I am trying to parse access_token string from the "Set-Cookie" header in the curl POST request executed every 10 seconds and store it in a variable.
This variable will need to be used to execute the GET request, which is every 5 minutes. The variable will be part of the request. The variable is is a access token cookie string that changes everytime the POST request is executed. This access token string will be used in the second curl request for it to run properly.
My question is, how to get only the text after "access_token=" and before the ";" ?
Code
echo $(curl -D text.txt -ivk -H "Content-type: application/json" --data '{"username":"username", "password":"password", "grant_type":"password" }' https://192.168.0.20/api/v1/auth/login | grep -Fi Set-Cookie)
echo $result
Terminal response
$ /c/Users/mark.fomin/Desktop/test1.sh
> POST /api/v1/auth/login HTTP/1.1
> Host: 192.168.0.20
> User-Agent: curl/7.70.0
> Accept: */*
> Content-type: application/json
> Content-Length: 73
>
} [73 bytes data]
* upload completely sent off: 73 out of 73 bytes
{ [5 bytes data]
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Type: application/json
< X-Powered-By: Plural
< Access-Control-Allow-Origin: *
< Cache-Control: no-store
< Pragma: no-cache
< Set-Cookie: access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJXQS0yMjAwIiwibmJmIjoxNjA3NDUzNDY5LCJleHAiOjE2MDc0NTM3Njl9.KG4GXVLaTQ1TCe2nxOIVjLAHZyGNizbgM0Wb94-dkZI ;refresh_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoicmVmcmVzaF90b2tlbiIsImlzcyI6IldBLTIyMDAiLCJuYmYiOjE2MDc0NTM0NjksImV4cCI6MTYwNzQ1Mzc2OX0.hjJ6Ik5k6mVd19Yb9XVVlojq0_EIL-AGkZnSXmtdGe0; Path=/api; Secure
< Content-Length: 462
< Date: Tue, 08 Dec 2020 18:51:08 GMT
< Server: lighttpd/1.4.45
<
{ [5 bytes data]
100 535 100 462 100 73 1113 175 --:--:-- --:--:-- --:--:-- 1286
* Connection #0 to host 192.168.0.20 left intact
Set-Cookie: access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJXQS0yMjAwIiwibmJmIjoxNjA3NDUzNDY5LCJleHAiOjE2MDc0NTM3Njl9.KG4GXVLaTQ1TCe2nxOIVjLAHZyGNizbgM0Wb94-dkZI ;refresh_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoicmVmcmVzaF90b2tlbiIsImlzcyI6IldBLTIyMDAiLCJuYmYiOjE2MDc0NTM0NjksImV4cCI6MTYwNzQ1Mzc2OX0.hjJ6Ik5k6mVd19Yb9XVVlojq0_EIL-AGkZnSXmtdGe0; Path=/api; Secure