Including Processes
You may #include (or #verbatim) process output within PIKT .cfg files, not just file content. This variant was added to address the difficult question: In a constantly changing systems environment, how do you manage, automatically if possible, to keep your PIKT configurations accurate and up-to-date? Process includes make possible the dynamic and automatic updating of configuration files.
The formats are
#include [As an example of the first format, you could do something like the following (in defines.cfg):] [or: #verbatim] #include " " [ ] [or: #verbatim] #include < > [ ] [or: #verbatim]
dst // TRUE if Daylight Savings Time now applies, // FALSE otherwise // at our site, `date +%Z` returns "CDT" if DST is in // effect, "CST" otherwise; substitute your own time // zone string as needed #verbatim [if [ `date +%Z` = "CDT" ]; then echo TRUE; else echo FALSE; fi]The process (within enclosing [] brackets)
if [ `date +%Z` = "CDT" ]; then echo TRUE; else echo FALSE; fiwill output either TRUE or FALSE depending on whether Daylight Savings Time applies. So, sometimes the preprocessor will see, in effect,
dst TRUEand at other times
dst FALSEIn this example, you don't have to worry about keeping the dst define up-to-date. The #include [
Another thing hard to keep up-to-date is your down systems list. Suppose you have a program, called downsys.pl, to determine your down systems. When invoked as 'downsys.pl 10' (where 10 is a timeout factor in seconds), typical downsys.pl output might be
geneva cracow paduaYou could then define down in your systems.cfg this way:
down // set '-H down' for these members #indent #include [/pikt/lib/programs/downsys.pl 10] #unindentNote that it is necessary to indent your [
downsys.pl might come up empty-handed, because it aborts due to a syntax error, or a timeout, or perhaps because there are no current down systems. In most cases--a 'members' stanza in systems.cfg being one exception--this will cause a parse error. To protect against this, it is entirely possible to intersperse #include [
down // set '-H down' for these members london rotterdam calais #verbatim [/pikt/lib/programs/downsys.pl 10] #includeSuppose the retiredsys_systems.cfg file content were
rheims orleans2(Note that these systems are indented within the file, hence it is unnecessary to wrap '#indent ... #unindent' around the #include directive, nor is it necessary to use #verbatim.)
After all file and process inclusions, the preprocessor would see, in effect,
down members london rotterdam calais geneva cracow padua rheims orleans2In the example just given, downsys.pl would be run every time the preprocessor sees that line in the configuration (in systems.cfg). If you have many systems to poll, that would of course slow things down considerably. You have the option to reference both an on-disk local file, as well as a process, with
#include "Either of these will have the preprocessor reference the on-disk" [ ] #include < > [ ]
You might think of the on-disk
In other words, suppose the directive were written as
#verbatimIf you specify the '-I' (for "update include files") piktc option, as in[/pikt/lib/programs/downsys.pl 10]
# piktc -cI +H piktmasterthis will read from [/pikt/lib/programs/downsys.pl 10] and write that process output to the file
Although you could use the '-I' routinely in all of your piktc commands, of course you shouldn't, for that would slow your piktc operations down dramatically. Better to do this just occasionally, say once a day (overnight) only.
To auto-update your configuration and refresh your scripts and data sets with the very latest and most accurate information on all systems, you could regularly schedule (e.g., nightly) the sequence
piktc -cI +H piktmaster piktc -iv ALLeither by cron'ing it or by having PIKT itself run it on the piktmaster machine.
When using '#include [
maxtime.exp // put a time limit on an invoked command #!=expect set timeout [lindex $argv 0] eval spawn -noecho [lrange $argv 1 end] expectYou might use this Expect script in downsys.pl written as:
#if piktmaster downsys.pl // list all down systems #!=perl # downsys.pl -- list all down systems die "Usage: downsys.plIf you are not careful, it's very easy to get the\n" if ($#ARGV != 0) ; foreach $sys (`=piktc -L +H all`) { chomp $sys ; next if (`=maxtime $ARGV[0] =ping $sys` =~ /is alive/) ; print "$sys\n" ; } #endif
Refer to the Introduction and Samples pages (or possibly also the lib/configs_samples files in the latest official software release, pikt-current.tar.gz, but view the cautionary README file in the configs_samples directory) for many more examples of this technique.
prev page | 1st page | next page |