-1

I found the value of a response (curl) with sed and now i need some help to take the value that i printed in a file and to use it in another substring in the same .sh script

This is the response of the server:

{"status":{"code":"STATUS_OK","message":"ServiceUUID sent successfully via..."},"body":{"data":{"userApps":{},"username":"HereTheUsername","fullName":"NameOfTheAccountPossessor","lang":"sq","blocked":false,"lastLogin":"2016-10-10T17:19:22","passwordResetUuid":"6147dc32-b72e-450a-8084-2fdb5319a931","userAccessLevel":5,"countDownSeconds":0,"serviceUuid":"7260276c-5c3f-41d3-9329-3603acecb7e5","userAttributes":{},"labelMap":{},"id":"APPUSER00000012","someLabel":"NameOfTheOrganisation"}}}

So i finded the value "serviceUuid":

fuid=$(echo "$uuid" | sed -nE 's/.*"serviceUuid":"(.*)","user.*/\1/p' >> final.txt)

Now i want to take this value(in file final.txt) and to paste it on this string in the same file of the script called aass.sh:

login=$(curl -X POST -H "ACCEPT-LANGUAGE:en"   -H "Content-Type: application/json;charset=utf-8" -H "Accept-Encoding:gzip"   -H "Accept: application/json" -d  {"serviceUuid":"**HERE**"} UrlOfTheSite)

How i can do?

  • 2
    If you're using Unix & Linux to do your homework, try organizing a list of questions relating to your script and putting them in the same question, instead of opening a new question for every step of your script, as here, and unix.stackexchange.com/questions/325181/… – Tim Kennedy Nov 22 '16 at 18:08
1

Assuming only the most recent uuid is stored in final.txt, this should do it...

service_uuid=$(cat final.txt)
login=$(curl -X POST -H "ACCEPT-LANGUAGE:en"   -H "Content-Type: application/json;charset=utf-8" -H "Accept-Encoding:gzip"   -H "Accept: application/json" -d  {"serviceUuid":"${service_uuid}"} UrlOfTheSite)

Without seeing your whole script it's a little difficult to know exactly what you expect in final.txt, but keep in mind that you're using the append redirect (>>) as opposed to overwrite (>) so that file will probably keep a running list of all uuid's the script recieves.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.