The macros in the sample output_macros.cfg configuration file below are for special handling script output. You would use these to control verbosity, to route messages in unusual ways, to send mail and reminder messages, etc.
///////////////////////////////////////////////////////////////////////////////
// output macros
///////////////////////////////////////////////////////////////////////////////
piktprinter r512ps
///////////////////////////////////////////////////////////////////////////////
// the verbose define controls whether certain routine messages get emailed
// or thrown away; in earlier versions of PIKT, this conditionality was
// handled in this way in alarms.cfg:
//
// #ifdef verbose
// output mail "truncated $inlin"
// #endifdef
//
// with the macros below, we can now achieve the same effect by replacing
// the above three lines with just this one line:
//
// =outputmail "truncated $inlin"
#ifdef verbose
outputmail output mail
#elsedef
outputmail output log "/dev/null"
#endifdef
// if verbose is not defined (is set to FALSE), the message is logged to
// /dev/null, that is, thrown away
//
// see the sample alarms.cfg for many more examples of this trick
///////////////////////////////////////////////////////////////////////////////
// the stifle define controls how often certain routine messages ("nagmail")
// are sent; in earlier versions of PIKT, this conditionality was handled
// in this way in alarms.cfg:
//
// #ifdef stifle
// if #fa % 7 == 0 // report only every 7 days
// output mail "orphaned?: $inline"
// endif
// #elsedef
// output mail "orphaned?: $inline"
// #endifdef
//
// with the macros below, we can now achieve the same effect by
// replacing the above seven lines with just these three lines:
//
// if #fa % =stifle7 == 0 // report only every 7 days
// output mail "orphaned?: $inline"
// endif
#ifdef stifle
stifle(N) (N)
#elsedef
stifle(N) 1
#endifdef
///////////////////////////////////////////////////////////////////////////////
output_other_mail(F, S, R, L) // output conditional mail to addressee(s)
// beyond those specified in the alert
// mailcmd; we don't #pclose() the (F)
// filehandle at the end, instead letting
// pikt do it, enabling us to make this a
// a one-liner macro
// (F) is the filehandle name (e.g., MAIL)
// (S) is the subject (e.g., 'check this out')
// (R) is the recipient (e.g., brahms\@hamburg)
// (L) is the line (e.g., $inline)
if ! #defined(#isopen(F))
set #isopen(F) = #false()
fi
if ! #isopen(F)
if #popen((F), "=mailx -s (S) (R)", "w") != #err()
set #isopen(F) = #true()
else
output mail "\#popen() failure for:
=mailx -s (S) (R)"
quit
fi
fi
do #write((F), (L))
///////////////////////////////////////////////////////////////////////////////
outputproc(C, P) // send all output from process (P) to communications
// channel (C)
// (C) is the comm channel (e.g., mail, syslog, print)
// (P) is the process (e.g., "=ll /tmp")
// sample use: =outputproc(mail, "=ll /tmp")
do #popen(OUTPUTPROC, (P), "r")
while #read(OUTPUTPROC) > 0
output (C) $rdlin
endwhile
do #pclose(OUTPUTPROC)
///////////////////////////////////////////////////////////////////////////////
outputfile(C, F) // send all output from file (F) to communications
// channel (C)
// (C) is the comm channel (e.g., mail, syslog, print)
// (F) is the file (e.g., "=crontabs/$name")
// sample use: =outputfile(mail, "=crontabs/$name")
do #fopen(OUTPUTFILE, (F), "r")
while #read(OUTPUTFILE) > 0
output (C) $rdlin
endwhile
do #fclose(OUTPUTFILE)
///////////////////////////////////////////////////////////////////////////////
outputlogfile(C, L) // send new entries in logfile (L) to communications
// channel (C)
// (C) is the comm channel (e.g., mail, syslog, print)
// (L) is the logfile (e.g., "=sulog")
// sample use: =outputlogfile(syslog, "=sulog")
// note: this takes the place of 'input logfile "..."'
init
input logfile (L)
rule
output (C) $inlin
///////////////////////////////////////////////////////////////////////////////
outputhdr(C, H) // out header (H) to communications channel (C), but
// only if the header has not already been output
// (C) is the comm channel (e.g., mail, syslog, print)
// (H) is the header (e.g.,
// $command("=ps -eo user,pid,comm =head -1"))
// sample use:
// =outputhdr(mail,
$command("=ps -eo user,pid,comm =head -1"))
if ! #defined(#outputhdr)
output (C) (H)
set #outputhdr = #true()
fi
///////////////////////////////////////////////////////////////////////////////
mailmsg1(M, S, R) // e-mail a one-line message (M) with subject (S)
// to recipient (R)
// (S) must be a single word, e.g., REMINDER
// use =mailmsg1() instead of =mailmsg2() in
// 'pikt +C' and #piktexec commands
// sample use: =mailmsg1(review the sudo group, REMINDER,
=piktadmin)
=execwait "echo (M) | =mailx -s (S) (R)"
///////////////////////////////////////////////////////////////////////////////
mailmsg2(M, S, R) // e-mail a one-line message (M) with subject (S)
// to recipient (R)
// (S) may be multiple words
// sample use: =mailmsg2($inlin, bad address,
$list\-owner)
=execwait "echo '(M)' | =mailx -s '(S)' (R)"
///////////////////////////////////////////////////////////////////////////////
remind(Y, M, D, MSG)
// send out a reminder message beginning at a certain date
// (Y) is the year (e.g., 2000)
// (M) is the month (e.g., 7)
// (D) is the date (e.g., 15)
// (MSG) is the message (e.g., "REVIEW DISK QUOTAS")
if #now() > #datevalue((Y), (M), (D))
output mail (MSG)
fi
// note: you should be careful to make sure that this reminder
// doesn't occur repeatedly starting at the trigger date, for
// example, by limiting it to just once per day on just one
// machine:
//#if madrid
// begin
// set #dy = #day()
// if #dy > %dy // repeat once daily
// =remind(2001, 7, 15, "REVIEW DISK QUOTAS")
// fi
//#endif
///////////////////////////////////////////////////////////////////////////////
[For more examples, see Samples.]
Home |
FAQ |
News |
Intro |
Samples |
Tutorial |
Reference |
Software |
Authors |
Licensing |
SiteSearch
Links |
SiteIndex |
Pikt-Users |
Pikt-Workers |
Contribute |
ContactUs |
Top of Page
Page best viewed at 1024x768.
Page last updated 2005-06-22.
This site is
PIKT®
powered.
PIKT® is a registered trademark of the University of Chicago.
Copyright © 1998-2005 Robert Osterlund. All rights reserved.
|