This section describes the debugging of Systemwalker Scripts using the following two examples.
Example of embedding a command used for debugging
Example of how to change the trace level
Example of Embedding a Command Used for Debugging
Below is an example of "15.3 Commands Used in Debugging" that have been embedded in a script.
Script file | Level (Note) | Output contents |
---|---|---|
# Open trace file. # Delete "level 2" when the script actually runs. set Trchwnd [sw_TcOpenTrace -level 2 /var/log/G001] if {$Trchwnd < 0} { puts stderr "Trace open err" exit 1 } # Output a start log record. sw_TcWriteTrace $Trchwnd "JOB001 START" # Acquire file name. set filename [lindex $argv 0] sw_TcWriteTrace -level 2 $Trchwnd "Input file name: $filename" # Open operation control file. if {[catch { set cid [open $filename r] }]} { # When an open error is captured, # output an error log record. sw_TcWriteTrace $Trchwnd "File open err (filename :$filename)" sw_TcCloseTrace $Trchwnd exit 1 } sw_TcWriteTrace -level 2 $Trchwnd "File opened " # Load file. set rc [gets $cid buf] if {$rc == -1} { # Since the file is empty, set the default in the read buffer. sw_TcWriteTrace -level 2 $Trchwnd "File empty " set buf 100 } sw_TcWriteTrace -level 2 $Trchwnd "Gets data: $buf" close $cid ... # Output an end log record. sw_TcWriteTrace $Trchwnd "JOB001 END" sw_TcCloseTrace $Trchwnd | 1 2 1 2 2 2 1 | Operation log Information in script (Route check) Error log Route check Route check Information in script (Route check) Operation log |
The numbers in the "Level" column indicate trace levels.
Since the trace level defaults to 1, its specification in commands is omitted.
Example of How to Change the Trace Level
To specify the trace level, use options of extended trace commands that are entered in Systemwalker Scripts. It is difficult to directly change the content of a script if the trace level needs to be changed when the script is running on Systemwalker Operation Manager. Thus, the following means is provided to allow you to change the trace level without changing scripts.
Specification using a script's argument
A trace level is passed via an argument used when a script is invoked.
# Obtain trace level from first argument set trclevel [lindex $argv 0] # Check the setting value if {$trclevel < 0 || $trclevel > 2} { # Setting value error puts stderr "trace level err :$trclevel" exit 1 } # Open trace. set Trchwnd [sw_TcOpenTrace -level $trclevel {c:\var\log\G001.trc}] ... sw_TcCloseTrace $Trchwnd exit 0
# Obtain trace level from first argument set trclevel [lindex $argv 0] # Check the setting value if {$trclevel < 0 || $trclevel > 2} { # Setting value error puts stderr "trace level err :$trclevel" exit 1 } # Open trace. set Trchwnd [sw_TcOpenTrace -level $trclevel /var/log/G001.trc] ... sw_TcCloseTrace $Trchwnd exit 0
Specification using an external file
A trace level is read from a file in which the trace level is entered.
# Open, read, and close the trace level description file. if {[catch { set cid [open {c:\home\etc\trclevel} r] gets $cid trclevel close $cid }]} { # Trace level description file error puts stderr "Can not read {c:\home\etc\trclevel}" exit 1 } # Check setting value. if {$trclevel < 0 || $trclevel > 2} { # Setting value error puts stderr "trace level err :$trclevel" exit 1 } # Open trace. set Trchwnd [sw_TcOpenTrace -level $trclevel {c:\var\log\G001.trc}] ... sw_TcCloseTrace $Trchwnd exit 0
# Open, read, and close the trace level description file. if {[catch { set cid [open /home/etc/trclevel r] gets $cid trclevel close $cid }]} { # Trace level description file error puts stderr "Can not read /home/etc/trclevel" exit 1 } # Check setting value. if {$trclevel < 0 || $trclevel > 2} { # Setting value error puts stderr "trace level err :$trclevel" exit 1 } # Open trace. set Trchwnd [sw_TcOpenTrace -level $trclevel /var/log/G001.trc] ... sw_TcCloseTrace $Trchwnd exit 0