[Contents] [Prev] [Next] [Index] [Report an Error]

Detecting Invalid Commands

In this example, the following macro file (badExecCommand.mac) is programmed to executes four exec mode commands. However, the second command in the sequence is invalid.

<# badExecCommandMacro #>
<# env.setResult("runStatus","start" ) #>
show clock
<# env.setResult("runStatus","after first show clock" ) #>
foo
<# env.setResult("runStatus","after foo" ) #>
show privilege
<# env.setResult("runStatus","after show privilege" ) #>
show clock
<# env.setResult("runStatus","complete" ) #>
<#endtmpl#>
<# onerror #>
<# errCmd := env.getErrorCommand #>
<# errStatus := env.getErrorStatus #>
<# env.setResult("commandError", errCmd) #>
<# env.setResult("commandErrorStatus", errStatus) #>
<#endtmpl#>

If the macro were to run to completion, the following commands would be executed:

show clock
foo
show privilege
show clock

Without the onError macro, the macro would indicate the invalid command, but it would also continue with the rest of the configuration. When using the onError macro, the macro stops when it encounters the invalid command.

Executing the macro that contains the onError macro, the output appears as follows:

host1# macro badExecCommandTest.mac badExecCommandMacro  
Macro 'badExecCommandMacro' in file 'badExecCommandTest.mac' starting execution (Id: 101)
SUN JAN 08 2005 07:21:50 UTC
ERX-40-94-fb#foo
             ^
% Invalid input detected at '^' marker.
Privilege level is 15
Macro 'badExecCommandMacro' in file 'badExecCommandTest.mac' ending execution (Id: 101)

You can determine the execution progress through the runStatus result entry in the macroData log file. For this example, the log output indicates the command error and displays the following to indicate that the macro ended early:

runStatus is after foo

host1# show log data category macroData severity debug
NOTICE 01/08/2006 07:14:13 macroData: Macro 'startmin' in file 'master.mac' starting execution (Id: 1) on vty, 0
NOTICE 01/08/2006 07:14:18 macroData: Macro 'startmin' in file 'master.mac' ending execution (Id: 1) on vty, 0
NOTICE 01/08/2006 07:21:50 macroData: Macro 'badExecCommandMacro' in file 'badExecCommandTest.mac' starting execution (Id: 101) on vty, 0
ERROR 01/08/2006 07:21:50 macroData: (Id: 101) Command error: foo, Command syntax error
NOTICE 01/08/2006 07:21:50 macroData: (Id: 101) commandError is foo
NOTICE 01/08/2006 07:21:50 macroData: (Id: 101) commandErrorStatus is Command syntax error
NOTICE 01/08/2006 07:21:50 macroData: (Id: 101) runStatus is after foo
NOTICE 01/08/2006 07:21:50 macroData: Macro 'badExecCommandMacro' in file 'badExecCommandTest.mac' ending execution (Id: 101) on vty, 0

[Contents] [Prev] [Next] [Index] [Report an Error]