Script Change Macro
The script_change_alarms_macros.cfg is a script macro to report script changes.
script_change(F, D, E, L) init status =piktstatus level =piktlevel task "Report changes in (F) scripts" input proc "=file (D)/* 2>/dev/null | =egrep -iv 'elf.+executable|directory|nohup\.out' | =awk -F: '{print $1}'" dat $fil 1 rule if $fil =~~ "(E)" next fi rule set #doheader = #true() rule set $hstfil = $substitute($fil, "/usr/local/acme", "=hstdir/acme") rule set #fmt[$fil] = #filemtime($fil) rule // make a history copy of all new scripts if ! #defined(%fmt[$fil]) if =offhours(#hour()) doexec wait "=cp -p $fil $hstfil" output log "(L)" "new script: $fil" fi next fi rule // bypass unchanged scripts if #fmt[$fil] <= %fmt[$fil] next fi rule // for changed scripts, diff and log/mail any changes if #popen(DIFF, "=diff $hstfil $fil", "r") != #err() while #read(DIFF) > 0 if #doheader output mail "changes to $fil:" output log "(L)" "changes to $fil:" set #doheader = #false() fi output mail $rdlin output log "(L)" $rdlin endwhile do #pclose(DIFF) else output mail "can't open process for reading!" quit fi if #doheader == #false() // so we entered the diff // loop above, have diff // output, hence require a // separator line output mail =newline fi rule // make a history copy of the newly changed script if =offhours(#hour()) doexec wait "=cp -p $fil $hstfil" fi end quit
You might invoke the =script_change() macro in your alarms.cfg file thusly:
/////////////////////////////////////////////////////////////////////////////// // // acme_alarms.cfg // /////////////////////////////////////////////////////////////////////////////// ACMEScriptChange =script_change(acme, =acmebindir, =nonesuch, =acmescriptchange_log) /////////////////////////////////////////////////////////////////////////////// CorbaScriptChange =script_change(corba, =acmebindir/corba.prod, cal\\\\.out|core, =corbascriptchange_log) ///////////////////////////////////////////////////////////////////////////////
Output from the ACMEScriptChange script might look like, for example:
NOTICE: ACMEScriptChange Report changes in acme scripts changes to /usr/local/acme/bin/run-acme: 37,38c37,38 < ## export DSQUERY=ORDB1 < export DSQUERY=DATABASE2 --- > export DSQUERY=ORDB1 > ## export DSQUERY=DATABASE2
For more examples, see Samples.