NIS passwd

[posted 2000/07/12]

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 seconds!

For more examples, see Developer's Notes.

 
Home | FAQ | News | Intro | Samples | Tutorial | Reference | Software
Developer's Notes | Licensing | Authors | Pikt-Users | Pikt-Workers | Related Projects | Site Index | Privacy Policy | Contact Us
Page best viewed at 1024x768 or greater.   Page last updated 2019-01-12.   This site is PIKT® powered.
Copyright © 1998-2019 Robert Osterlund. All rights reserved.
Home FAQ News Intro Samples Tutorial Reference Software
PIKT Logo
PIKT Page Title
Learn about
Pikt script
operators &
expressions