HPE OneView
1819794 Members
3423 Online
109607 Solutions
New Discussion юеВ

getting error, but command works for changing server power state

 
SOLVED
Go to solution
BradV
Esteemed Contributor

getting error, but command works for changing server power state

The command is working, but I am getting a parse error: Invalid numeric literal at line 1, column 9

DATA='{"powerState":"Off","powerControl":"MomentaryPress"}'
curl --insecure \
       --header "content-type: application/json" \
       --header "X-API-Version: ${currentVersion}" \
       --header "auth: ${sessionID}" \
       --include \
       --data "${DATA}" \
       --request PUT ${OneView}/rest/server-hardware/{id}/powerState | jq -r '.'

The server is powering off, but I'm getting that error.  If I change the powerState to On and apply, that works also, but with the same parse error.  Anyone have a clue what could be wrong?

5 REPLIES 5
ChrisLynch
HPE Pro

Re: getting error, but command works for changing server power state

This is an error within Bash, and your use of jq.  I found a thread on this over on Stackoverflow.  The HTTP response from this request will be either an HTTP Error (400-, 500- series code) or HTTP 202 for success.  There will be no JSON response until you get the Location HTTP header for the async task from the HTTP 202 response.  Otherwise, what are you trying to parse with jq in your pipeline?

I work at HPE
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
BradV
Esteemed Contributor

Re: getting error, but command works for changing server power state

Hi Chris,

I have no idea. 

It's my standard response when sending a command to the REST API.  I'll remove it and see what messages I'm receiving.  It is working.  So, that part is good.

Thanks!

ChrisLynch
HPE Pro

Re: getting error, but command works for changing server power state

I'm no Bash expert, but I can't see why one would use jq here when the reply doesn't include a JSON reply. If it did, and you wanted to parse the response, then it could be used.
I work at HPE
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
Accept or Kudo
BradV
Esteemed Contributor

Re: getting error, but command works for changing server power state

No, totally my fault.  I did not look at the specs close enough to notice it was not a json output.  Sorry!

BradV
Esteemed Contributor
Solution

Re: getting error, but command works for changing server power state

I fixed with:

DATA='{"powerState":"Off","powerControl":"MomentaryPress"}'
TASKURI=$(curl --insecure \
       --header "content-type: application/json" \
       --header "X-API-Version: ${currentVersion}" \
       --header "auth: ${sessionID}" \
       --include \
       --data "${DATA}" \
       --request PUT ${OneView}/rest/server-hardware/{id}/powerState |  grep '^Location:' | awk '{ print $2})

Can then check the status of the task with:

curl --insecure \
       --header "X-API-Version: ${currentVersion}" \
       --header "auth: ${sessionID}" \
       --request GET ${OneView}${TASKURI} | jq -r '.'