[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [K12OSN] How to change X-terminales networks

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).

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.

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).

The script is as follows. Al comments and improuvements are welcome.

# ---------------- SCRIPT BEGINS -------------------

# Files involved in lts
@FILES=qw( /etc/dhcpd-k12ltsp.conf
# function to calculate "C" class subnets.
sub calc_subnet {
   my $IP=$_[0];
   return substr($IP,0,rindex($IP,".")+1);

# checking all available interfaces.
open (IFCONFIG, "/sbin/ifconfig |");
while (<IFCONFIG>) {
   @linea = split;
   if ($_ =~ /^[a-z].*/) {
   if ($_ =~ /inet addr.*/) {
      $IPS[$neth] = substr($linea[1],5);
close (IFCONFIG);

# checking active ltsp network
open (LTSCONF, $FICHERO) || die( "\nERROR: File $FICHERO not found\n");
while (<LTSCONF>) {
   @linea = split;
   if ($linea[0] eq "SERVER") {

# showing available interfaces, and actual lts interface.
print "\nAvailable interfaces:\n\n";
for ($i=0;$i<$neth;$i++) {
   print $IPS[$i]," \t ",$ETHS[$i];
   if ($ACTUALIP eq $IPS[$i]) {
      print " (actual lts interface)";
#      $OLDNET=$OLDSUBNET."0";
#      $OLDBCAST=$OLDSUBNET."255";
   print "\n";

# Asking for new lts interface
print "\nNew lts interface (ethx): ";

# looking for ip associated to the new lts interface.
for ($i=0;$i<$neth;$i++) {
   if ($NEWETH eq $ETHS[$i]) {
#      $NEWNET=$NEWSUBNET."0";
#      $NEWBCAST=$NEWSUBNET."255";

# If introduced interface is no one of the existents.
if ( $i == $neth ) {
   die ("Sorry, unknown interface $NEWETH. Process cancelled.");

print "The following files will be changed to new subnet $NEWSUBNET\n";
print "and .bak backup copies will be generated:\n\n";
print "";
foreach $file (@FILES) {
   print $file."\n";

print "\nDo you agree (y/n)? ";
if ( lc($res) ne "y" && lc($res) ne "yes" ) {
   print "\nBye ..!!! \n";

# check all files do exists; in case ALL are not there, cancel process.
foreach $file (@FILES) {
   if (! -e $file) {
      die("\nFile $file not found. No file changed. Process canceled");

# Go ahead ....!!!
print "\n";
foreach $file (@FILES) {
   print "changing file ".$file."\n";
   system( "/bin/sed -i.bak 's/$OLDIP/$NEWIP/g;s/$OLDSUBNET/$NEWSUBNET/g' $file" );

print "\nProcess finished. Do not forget to check 'range dynamic-bootp'";
print "\nin /etc/dhcpd-k12ltsp.conf, and restart dhcp and nfs services.\n";
print "\nCheck too /etc/hosts for the new name of the server\n\n";

# ---------------- SCRIPT ENDS ----------------------


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]