Home > database >  Return reponse status from shell script curl command
Return reponse status from shell script curl command

Time:12-24

I have a shell creates a tenant in a pulsar cluster. My question is less specific to that. In the below script, how do I get a response verification? I'd like to use a conditional to confirm that the PUT got a 200 or not.

### 
### Set up resources
###

CLUSTER=standalone
TENANT=sandbox

# Create tenant
curl -L -X PUT "http://localhost:$HOST_PORT/admin/v2/tenants/$TENANT" \
    --header 'Content-Type: application/json' \
    --data-raw "{\"allowedClusters\": [\"$CLUSTER\"]}"

CodePudding user response:

The variable $? contains the return code of the last command. You can check that for a non-zero value after curl command.

CodePudding user response:

You can use the --fail option of curl. With this option, if the PUT is not a success, then the curl command return value will be non zero.

  • Related