#!/usr/bin/perl # # Examines the cfengine public key directory on the server, finds keys # for all hosts cfengine knows about, and generates a new cfrun.hosts # file to stdout. # # David J. Bianco # use Socket; $PPKEYS="/var/cfengine/ppkeys"; $PPKEYS_REGEXP=".*-([0-9]+.[0-9]+.[0-9]+.[0-9]+)\.pub"; # First, open the key directory so we can read the file list opendir(PPDIR, $PPKEYS) || die "Can't open cfengine key dir: $!\n"; $keyfilename = readdir PPDIR; while(defined $keyfilename) { if($keyfilename =~ m/$PPKEYS_REGEXP/g) { $ip = $1; $addr = inet_aton($ip); $hostname = gethostbyaddr $addr, AF_INET; # Customzie this next line to include your own domain name $hostname =~ m/(.*).jlab.org/; $hostname = $1; print "$hostname\n"; } $keyfilename = readdir PPDIR; }