Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

Running BASH commands via REST API

I am trying to run bash commands via the REST API but am getting an error. When trying to use the following syntax I am getting a 403 running with Admin authentication...

GET: https://F5LTM/mgmt/tm/util/bash

Output: {"code":403,"message":"Operation is not allowed on component /util/bash.","errorStack":[]}

Does anyone know if this is possible, or have any syntax examples of how to run bash commands? I assume you need to submit a post request, but I am not sure how to structure the syntax in the body of the request and cannot find any examples.

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi Tim,

Take a look to the example below to see the required format of the request...

curl -vsk -u 'admin:admin' -H "Content-Type: application/json" -X POST https://YOURDEVICE/mgmt/tm/util/bash -d "{\"command\":\"run\",\"utilCmdArgs\":\"-c 'echo "Hello World!"'\"}"

Cheers, Kai

0
Comments on this Answer
Comment made 08-Feb-2017 by Tim Harber 56

Thanks for this. I am using Postman instead of CURL. The passed argument doesn't seem to give the expected results. I receive:

{"code":415,"message":"Found invalid content-type. The content-type must be application/json. The received content-type is c9819cad-78a7-0b75-6033-582e26b2a202","errorStack":[]}

I am passing it as JSON, so I assume something with the formatting needs to be changed. Any suggestions?

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi Tim,

try these Postman settings...

Request Settings:

Method: POST
URL: https://YOURBOX/mgmt/tm/util/bash
Authorization: BasicAuth = YourCredentials
Headers: Content-Type = application/json
Body: {"command":"run","utilCmdArgs":"-c 'echo \"Hello World\"'"}

Note: You can also set the Content-Type on Postmans "Body" pane. Click on the down arrow to see the predifined JSON setting...

Expected Result:

{
  "kind": "tm:util:bash:runstate",
  "command": "run",
  "utilCmdArgs": "-c 'echo \"Hello World\"'",
  "commandResult": "Hello World\n"
}

Cheers, Kai

0