Forum Discussion
mvo_65102
Jan 30, 2017Nimbostratus
Native tmsh/bash commands via REST API
Hi all,
is there a way to execute native tmsh or bash commands using the REST API?
As long as there are not all configurations controllable by REST i would like to execute some commands directly...
Satoshi_Toyosa1
Sep 06, 2018Ret. Employee
To list virtuals under the partition /Test directly from bash, for example, you can use
echo
to pass multiple statements to tmsh:
bash -c 'echo "cd /Test; list ltm virtual" | tmsh'
That's what you want to send to the
/mgmt/tm/util/bash
endpoint. e.g.,
curl -sku admin:admin https://192.168.184.30/mgmt/tm/util/bash \
-X POST -H "Content-Type: application/json" \
-d "{\"command\":\"run\", \"utilCmdArgs\":\"-c 'echo \\\"cd /Test; list ltm virtual\\\" | tmsh'\"}"
Example output:
{
"command": "run",
"commandResult": "ltm virtual testvs {\n destination 172.16.10.45:http\n ip-protocol tcp\n mask 255.255.255.255\n partition Test\n pool /Common/CentOS-All\n profiles {\n /Common/tcp { }\n }\n source 0.0.0.0/0\n translate-address enabled\n translate-port enabled\n vs-index 7\n}\n",
"kind": "tm:util:bash:runstate",
"utilCmdArgs": "-c 'echo \"cd /Test; list ltm virtual\" | tmsh'"
}
Please be careful with the escaping sequences.
If you have a more complex tmsh call, consider writing a tmsh script and call it via the
/mgmt/tm/cli/script
endpoint: e.g.,
curl -sku admin:admin https://192.168.184.30/mgmt/tm/cli/script
Obviously, it does not make any sense calling tmsh via bash via tmsh (the iControl REST is just a wrapper for tmsh). Look for an endpoint that you can call directly for your purpose.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects