One of the goals for tmsh scripting was to reduce the amount of screen scraping (run command | grep | grep ...) that had to be done.
There are two commands, tmsh::get_config (list command equivalent) and tmsh::get_status (show command equivalent) that provide structured/programmatic access to config, stats and status. You don't have to use grep. You just need the names of the fields that you are interested in. For tmsh::get_config the field names are what you see in list command output (list ltm virtual). For tmsh::get_status the field names are what you see in show command output with the field-fmt option.
One of the benefits of these API calls is that they allow you to write a script that will not fail in the future when we add something to the output of "sh net vlan" that happens to have the string "Mac" in it.
If you issue this command you will see the mac-true field.
tmsh show net vlan field-fmt
You can then write scripts that access the fields you see in the output of "show field-fmt".
Here is a script that displays the mac of each vlan.
cli script vlan_macs {
proc script::run {} {
foreach obj [tmsh::get_status /net vlan] {
puts "[tmsh::get_name $obj] [tmsh::get_field_value $obj mac-true]"
}
}
}
tmsh run cli script vlan_macs
There is more API info here.
help cli cript
That being said, I took a look at the source code and we do in fact ignore the pipe character in script mode. We will revisit that decision to determine if | should be allowed in a script.