Forum Discussion
Satoshi_Toyosa1
Sep 06, 2018Employee
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.