#!/usr/bin/perl # $Id: netlint-update,v 1.10 2008/04/02 21:15:37 anderson Exp $ # we expect to be called from /etc/aliases like this: # "| lockf -t 300 $UDIR netlint-update" use Getopt::Std; use strict; my($progname, %opts); $progname = $0; $progname =~ s/.*\///; getopts("Vh", \%opts); if (1 == $opts{'V'}) { print "$progname: " . '$Id: netlint-update,v 1.10 2008/04/02 21:15:37 anderson Exp $' . "\n"; exit 0; } if (1 == $opts{'h'}) { print "$progname: usage [-V | -h]\n"; print "V show version information\n"; print "h show this help message\n"; exit 0; } my($updir, $tmp, $host, $body, $host); $updir = "/var/netlint"; $tmp = "/tmp/netlint.$$." . int(rand(1000)); umask(022); die "$progname: open: $tmp: $!\n" unless open(TEMP, "> $tmp"); $body = 0; $host = ''; while() { # we don't want the headers; we only care about the body if (/^$/) { $body = 1; next; } if ($body) { print TEMP $_; next; } # we need to look in the subject to figure out the hostname if (m/^Subject: NETLINT: (.*)$/) { $host = $1; } if (m/^Subject: HOSTLINT: (.*)$/) { $host = $1; $updir = "/var/hostlint"; } } close(TEMP); die "$progname: misconfigured, as $updir is not here\n" unless -d "$updir"; die "$progname: oops, didn't get a host in the Subject.\n" unless $host; # ok, we've got the entire message, and a hostname. move it into our # reporting directory with ksb install(1) exit unless -s "$tmp"; unlink("$updir/$host") unless -s "$updir/$host"; exec('/usr/local/bin/install', '-m', '644', '-q', '-1', $tmp, "$updir/$host");