Forum Discussion

Tim_Harber's avatar
Feb 08, 2017

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.

3 Replies

  • 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

  • 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