Forum Discussion
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.
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
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
I also needed this as I was getting the same error , when trying to start bash scripts with REST-API. The other idea I was going to try is to use tmsh script (https://clouddocs.f5.com/api/tmsh/script__run.html ) as the example https://community.f5.com/t5/codeshare/creating-a-tmsh-script-with-icontrol-rest-and-using-it-to/ta-p/290984 and use the "tmsh::run util bash -c " in the script then trigger with API endpoint "mgmt/tm/cli/script" but that seemed too complex for a simple bash command.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com