In our NIS passwd file, we indicate the expiration date for temporary accounts in the gecos field, for example,
slatkin:j0VGd53v8a4zA:33169:46:Leonard Slatkin, 07/01/00:/home/perf/slatkin: /local/bin/tcsh
This is the script we run to signal that accounts are due to be expired:
#if nismaster YPPasswdChkNotice init status active level notice task "Check for retirable accounts" input file "/etc/NIS/passwd" seps ":" =passwddata rule =set_lineage($gecos) if #lineage > 0 output mail $inline endif #endif // nismaster
Unfortunately, this script takes forever to run through the 37,000+ line NIS passwd file on our old, slow (and soon to be replaced) nismaster machine. The culprit here is the =set_lineage() macro, which expands to four or more different regexp checks for each and every input line.
What to do?
We could rewrite YPPasswdChkNotice to invoke a separate Perl script, since Perl is so blindingly fast. (I'll be the first to admit that Pikt is not very fast. Maybe one day Pikt will be optimized for speed, but for now speed of execution is not Pikt's priority.)
Or, with a simple tweak, we can let Pikt stay on the job. We have added the AWK filter statement below:
#if nismaster YPPasswdChkNotice init status active level notice task "Check for retirable accounts" input file "/etc/NIS/passwd" filter "awk -F: '$5 ~ /[0-9][0-9]/'" seps ":" =passwddata rule =set_lineage($gecos) if #lineage > 0 output mail $inline endif #endif // nismaster
Filtering the NIS passwd file through the awk one-liner has the Pikt
script processing just a hundred or so lines as opposed to all 37,000+.
This has reduced the script execution from a couple hours down to just 22
For more examples, see Developer's Notes.