Statements
In Pikt scripts (and excepting the script/stanza name, in the leftmost column), every statement begins with a statement keyword. Most you have seen already:
KEYWORD ATTRIBUTE init begin rule end status active|inactive level emergency|alert|critical|error| warning|notice|info|debug task "<alarm description>" input proc|process "<process>" file "<filename>" logfile "<filename>" filter "<process>" seps|separators "<separators>" dat|data <data specifier> keys <var> [<var> ...] if <conds> elif|elsif|elseif <conds> endif|fi while <conds> endwhile repeat until <conds> for <set statement> <cond> <set statement> <string var> in <keys function> endfor foreach <keys function> endforeach break continue|cont switch <string or numerical expression> case <character or number> default breakswitch|breaksw endswitch|endsw again leave redo next skip <numerical expression> last pause <numerical expression> quit die "<message>"Here are the rest of the statement keywords:
KEYWORD ATTRIBUTE do <function call> set <var> = <expr> unset|delete <var[]> exec [wait] "<process>" output [mail "<message line>"] [print "<message line>"] [log "<logfile>"|piktlog|syslog "<message line>"]"do" is akin to a nullop. You use it when when you want to make a function call for its side effects (e.g., when opening a file with #fopen() or splitting a string with #split()) and you don't care about the return value (but maybe you should!).
"set" is for assigning values (either string or numerical expressions) to variables. Performing a set on a dat variable is illegal (input data assigned to dat variables cannot be overridden). Illegal, too, is performing a set on a filehandle (e.g., FOO), preceding variable (e.g., @foo), and previous variable (e.g., %foo); once assigned (in the preceding/previous case by Pikt itself internally), these values may not be changed. An exception is a file handle opened then closed; it may then be reassigned to with a subsequent open function.
A special form of the set action appears in a for statement. For example,
for #i=0 #i<10 #i+=1The "#i=0" and #i+=1" are implied set actions, but in this context the set keyword is neither necessary nor allowed. To repeat: parentheses, however, are. This is legal:
for (#i=0 #i<10 #i+=1)Use whatever form you're comfortable with (although using parentheses can, in unusual circumstances, be problematic; it's best not to use them).
The 'unset' keyword (aka 'delete') removes an element from an associative array, for example:
unset $shell["daemon"]or, equivalently:
delete $shell["daemon"]"exec" is for executing a command string when you don't care about the return value (otherwise you could use "do #system()" or "do $command()"). "exec wait" temporarily halts the script run until the exec'ed command finishes. You would normally use exec wait, resorting to just plain exec for unusually time-consuming exec'ed commands.
The "output" statement is akin to other language's "print". When used as
output "<message line>"the text string is sent to the user screen (stdout). Usually, output is sent as e-mail using the statement
output mail "<message line>"Print output, or output to a logfile, is achieved by inserting the keyword "print", or the appropriate log keyword after the "output". "output piktlog" outputs to the current alert's log file (e.g., Urgent.log), "output syslog" logs to the system log (syslog), and "output log "<logfile>"" logs to the special log file specified
In Pikt, you achieve the functionality of other language's printf() by means of the string formatting functions.
When run non-interactively (i.e., when called without human intervention by piktd), or when run at the command line but with either the +M or +L options, pikt queues mail and print message lines until the end of its program run, only sending out e-mail or dumping to a printer just before pikt terminates. In "log" statements, on the other hand, the message line is logged to the current alert log, to syslog, or the special log file immediately.
There are no practical limits to the number of Pikt script statements, nor to the number of rules. There can be only one init, begin and end section, though.
![]() | 1st page | next page ![]() |