After trying all advices you gave me in all posts, I finally decided to code a perl script to change involved files. I am quite far from being a perl expert (I use it two or three times a year), but I have done something than seems to work (at least, it works for me).<br>
<br>I have put variable names and comments in English, so that interested ones have it easier to follow it than in spanish (my mother tongue). My English, as my perl, is not perfect either, sorry about that.<br><br>The scrip is considering all interfaces are "C" class, and it has been coded and tested in an k12ltsp-el5 system. The only thing to care about is the new dhcp-range, that after conversion may yield abnormal IP ranges (I haven't cared about correcting that, I find it simpler to change just that in the config file than making more code).<br>
<br>The script is as follows. Al comments and improuvements are welcome.<br><br># ---------------- SCRIPT BEGINS -------------------<br>#!/usr/bin/perl<br><br># Files involved in lts<br>@FILES=qw( /etc/dhcpd-k12ltsp.conf<br>
           /etc/exports<br>           /etc/hosts<br>           /etc/hosts.allow<br>           /opt/ltsp/i386/etc/lts.conf<br>           /opt/ltsp/ppc/etc/lts.conf<br>         );<br>         <br># function to calculate "C" class subnets.<br>
sub calc_subnet {<br>   my $IP=$_[0];<br>   return substr($IP,0,rindex($IP,".")+1);<br>}   <br><br># checking all available interfaces.<br>open (IFCONFIG, "/sbin/ifconfig |");<br>$neth=0;<br>while (<IFCONFIG>) {<br>
   @linea = split;<br>   if ($_ =~ /^[a-z].*/) {<br>      $ETHS[$neth]=$linea[0];<br>   }<br>   if ($_ =~ /inet addr.*/) {<br>      $IPS[$neth] = substr($linea[1],5);<br>      $neth++;<br>   }<br>}<br>close (IFCONFIG);<br>
<br># checking active ltsp network <br>$FICHERO="/opt/ltsp/i386/etc/lts.conf";<br>open (LTSCONF, $FICHERO) || die( "\nERROR: File $FICHERO not found\n");<br>while (<LTSCONF>) {<br>   @linea = split;<br>
   if ($linea[0] eq "SERVER") {<br>      $ACTUALIP=$linea[2];<br>   }<br>}<br>close(LTSCONF);<br><br># showing available interfaces, and actual lts interface.<br>print "\nAvailable interfaces:\n\n";<br>
for ($i=0;$i<$neth;$i++) {<br>   print $IPS[$i]," \t ",$ETHS[$i];<br>   if ($ACTUALIP eq $IPS[$i]) {<br>      print " (actual lts interface)";<br>      $OLDETH=$ETHS[$i];<br>      $OLDIP=$IPS[$i];<br>
      $OLDSUBNET=calc_subnet($OLDIP);<br>#      $OLDNET=$OLDSUBNET."0";<br>#      $OLDBCAST=$OLDSUBNET."255";<br>   }<br>   print "\n";<br>}   <br><br># Asking for new lts interface<br>print "\nNew lts interface (ethx): ";<br>
$NEWETH=<stdin>;<br><br># looking for ip associated to the new lts interface.<br>chomp($NEWETH); <br>for ($i=0;$i<$neth;$i++) {<br>   if ($NEWETH eq $ETHS[$i]) {<br>      $NEWIP=$IPS[$i];<br>      $NEWSUBNET=calc_subnet($NEWIP);<br>
#      $NEWNET=$NEWSUBNET."0";<br>#      $NEWBCAST=$NEWSUBNET."255";<br>      last;<br>   }<br>}<br><br># If introduced interface is no one of the existents.<br>if ( $i == $neth ) {<br>   die ("Sorry, unknown interface $NEWETH. Process cancelled.");<br>
}       <br><br>print "The following files will be changed to new subnet $NEWSUBNET\n";<br>print "and .bak backup copies will be generated:\n\n";<br>print "";<br>foreach $file (@FILES) {<br>   print $file."\n";<br>
}<br><br>print "\nDo you agree (y/n)? ";<br>$res=<STDIN>;<br>chomp($res);<br>if ( lc($res) ne "y" && lc($res) ne "yes" ) {<br>   print "\nBye ..!!! \n";<br>}<br><br># check all files do exists; in case ALL are not there, cancel process.<br>
foreach $file (@FILES) {<br>   if (! -e $file) {<br>      die("\nFile $file not found. No file changed. Process canceled");<br>   }<br>}   <br><br># Go ahead ....!!!<br>print "\n";<br>foreach $file (@FILES) {<br>
   print "changing file ".$file."\n";<br>   system( "/bin/sed -i.bak 's/$OLDIP/$NEWIP/g;s/$OLDSUBNET/$NEWSUBNET/g' $file" );<br>}   <br><br>print "\nProcess finished. Do not forget to check 'range dynamic-bootp'";<br>
print "\nin /etc/dhcpd-k12ltsp.conf, and restart dhcp and nfs services.\n";<br>print "\nCheck too /etc/hosts for the new name of the server\n\n";<br><br># ---------------- SCRIPT ENDS ----------------------<br>
<br>Regards,<br><br>