Next Previous Contents

10. A useful script

With your TFTP server recording transfered files into syslog you can use the following script to automatically remove the symlinks in the /tftp/pxelinux.cfg/ directory for each machine. The script watches for a string like tftpd[...]: Serving Kickstart_end to 192.168.0.11:32768. This indicates that the machine with IP address 192.168.0.11 loaded the marker file as the last action before the reboot after Kickstart is done.

Note that from version atftp-0.4 to atftp-0.5 the output format changed sightly. The following script matches the format of atftp-0.5 and later.

Start this script on your TFTP server(s) with the command

./PXEcfg_changer.pl
Press CTRL-c to terminate the program.

You are now able to start an installation on a whole bunch of machines without worrying about missing one link with the consquence that the machine would do its installation again (and again (and again (...))).

#!/usr/local/bin/perl -w
#
# Author: Alf Wachsmann, <alfw@slac.stanford.edu>, August 15, 2002
# Name of script: PXEcfg_changer.pl
# Version 2.0
# usage:
#        $path/PXEcfg_changer.pl

use strict;

use vars qw($VERSION $PRG $PATH);

my $debug   = 0;
my $verbose = 1;
my $file = '/var/log/messages';

$VERSION =  '2.0';
$PRG     =  $0;
$PRG     =~ s{(.*/)}{};
$PATH    =  $1;


my $PXEtftpPATH = "/tftp/pxelinux.cfg";
my $PXEdefault  = $PXEtftpPATH."/default";
die("Directory '$PXEtftpPATH' does not exist!") unless (-d $PXEtftpPATH);
die("File '$PXEdefault' does not exist!") unless (-f $PXEdefault);

my $hexIP_prefix = uc(sprintf("%02x", 192).sprintf("%02x", 168));

my $pid = open(INPUT, "/usr/bin/tail -n 1 -f $file |");
$SIG{INT} = $SIG{TERM} = sub { system("kill $pid") };

while (<INPUT>) {

  # this regexp matches output from atftp-0.6 that looks like this:
  # tftpd[9960]: Serving Kickstart_end to 192.168.0.11:32768
  next unless $_ =~ /tftpd\[\d+\]: Serving Kickstart_end to 192\.168\.(\d+)\.(\d+):\d+$/;
  my $hexIP = uc(sprintf("%02x", $1).sprintf("%02x", $2));

  print "unlink($PXEtftpPATH/$hexIP_prefix$hexIP)\n" if $debug|$verbose;
  unlink($PXEtftpPATH."/".$hexIP_prefix.$hexIP) unless $debug;
}


Next Previous Contents