Forum Discussion

Ted_Fines_13095's avatar
Ted_Fines_13095
Icon for Nimbostratus rankNimbostratus
Aug 05, 2013

TMSH error handling / exit codes

How do I use error handling / exit code checking in TMSH scripts?

 

For example, tmsh::create may be used to create a SNAT. If however the SNAT already exists, the script stops. How do you just get a return code from a tmsh command like tmsh::create and have the script accordingly?

 

e.g. Like the below pseudocode would do. I use this specifically because I have a need to add additional origin IPs to a domain if it exists, but to create a domain if it does not exist.

 

proc script::run { } {

 

RESULT=tmsh::create ltm snat my.domain.com origins add \{ 10.1.2.3 \} translation 8.9.10.11

 

if (RESULT = 0) {

 

puts "Hey, it worked."

 

} else {

 

puts "It failed. Error code=$RESULT"

 

}

 

}

 

 

Thanks in advance.

 

1 Reply

  • uni's avatar
    uni
    Icon for Altostratus rankAltostratus

    Check the TCL "catch" command (http://wiki.tcl.tk/902). It is also discussed in the context of an iRule here https://devcentral.f5.com/articles/irules-101-07-catch, but it is a TCL command, not an iRule specific one.