View Single Post
Old 05-02-2005, 01:14 AM  
SplitInfinity
Confirmed User
 
Join Date: Dec 2002
Location: San Diego, CA
Posts: 3,047
Some helpful scripts I wrote... leech them here.

First one...

PHP Code:
#!/usr/bin/perl


# SplitInfinity Networks, INC.
# 858-560-2760
# Programmer: Chris Jester
[email protected]
# This program is free to use, but not to sell.
# Enjoy.

# Compatible and tested on Fedora Core 1,2,3 etc.
# As well as any other Linux that uses /etc/sysconfig/network-scripts
# as a mechanism to add ips and etc. Redhat, Suse, Etc.
# This shell script, was created for admins to easily
# add many ip's to one server. Make a list of the IP's
# in a file called iplist.txt which is to be created
# in the same directory as the one this program resides
# in (unless you modify the paths below).
# Run the program from the shell prompt like this:

# ./makeips.pl START_WITH_WHAT#
#
# Where START_WITH_WHAT# is the number of the first interface
# you wish to begin with. So for example, if you have already
# assigned ethernet 0, 0:0 and 0:1 then you will want to add
# interfaces beginning at 0:2 so you would enter 2 there to
# make sure the numbering is correct and your new interfaces
# are created correctly.  If you are adding interfaces to
# a system with more than 1 ethernet card, then you must
# specify the card by changing the variable below.
#
# Props: Special thanks to Swami who inspired me to write
# this quick hack. Customers make the world go round.
# My scripts make it happen a bit faster. Thanks.

$interface    =     $ARGV[0];
$card        =    "0";

$directory    =    "/root/test";
#$directory    =    "/etc/sysconfig/network-scripts";
$iplist        =    "./iplist.txt";



open(DB,"$iplist");

while(<
DB>) {

# Template of the ip configuration file
$template = <<__END_OF_FORMAT__;
DEVICE=eth<<CARD>>:<<INTERFACE>>
ONBOOT=yes
BOOTPROTO
=static
IPADDR=<<IPADDRESS>>
NETMASK=255.255.255.0
GATEWAY
=<<GATEWAY>>
__END_OF_FORMAT__

    $ipaddress 
$_;
    
chomp($ipaddress);
    (
$oct1,$oct2,$oct3) = split(/\./,$ipaddress);
    
$gateway "$oct1.$oct2.$oct3.1";
    
    
$template =~ s/<<IPADDRESS>>/$ipaddress/g;
    
$template =~ s/<<INTERFACE>>/$interface/g;
    
$template =~ s/<<GATEWAY>>/$gateway/g;
    
$template =~ s/<<CARD>>/$card/g;

    
open(FILE">$directory/ifcfg-eth$card:$interface");
    print 
FILE $template;
    
close(FILE);

    
$shell .= "ifup ifcfg-eth$card:$interface\n";

    
$interface++;
    
    }

print 
$shell;
print 
"\n\n\nCopy the above commands and paste into shell to bring the new interfaces up.\n"
Second one...
PHP Code:
#!/usr/bin/perl



# Another script to make my life easy.
# Purpose: Lets say you have a bunch of domains to add to a
# name server. And each domain is to have its own settings...
# This script takes a file input in the following format:
#
# domain.com    ns1ip    ns2ip
# Where ns1ip is the primary ns and ns2ip is the secondary ns.
# This script will create all the zone files and spit out
# the entries to add to named.conf to make those zone files
# active.
# It will use ns1ip as the web server ip address. (since thats
# what I needed it to do when I wrote it. )
# Enjoy

$directory    =    "/var/named";
$domainlist        =    "./domains.txt";

open(DB,"$domainlist");

while(<
DB>) {

# Template of the ip configuration file
$template = <<__END_OF_FORMAT__;
\
$TTL 1800
\@       IN      SOA     ns1.<<DOMAINNAME>>. si-support.splitinfinity.net.  (
                                      
2005043100 Serial
                                      28800      
Refresh
                                      14400      
Retry
                                      3600000    
Expire
                                      1800 
)     ; Minimum

                IN      NS      ns1
.<<DOMAINNAME>>.
                
IN      NS      ns2.<<DOMAINNAME>>.

                
IN      MX      5       mail

                        A       
<<NS1IP>>
                
IN      A       <<NS1IP>>
mail            IN      A       <<NS1IP>>
www             IN      A       <<NS1IP>>

ns1                IN        A        <<NS1IP>>
ns2                IN        A        <<NS2IP>>

*                
IN        A        <<NS1IP>>
__END_OF_FORMAT__

    $input 
$_;
    (
$domainname,$ipaddress1,$ipaddress2) = split(/\t/,$input);
    
chomp($ipaddress2);

    
$template =~ s/<<NS1IP>>/$ipaddress1/g;
    
$template =~ s/<<NS2IP>>/$ipaddress2/g;
    
$template =~ s/<<DOMAINNAME>>/$domainname/g;

    
open(FILE">$directory/$domainname.zone");
    print 
FILE $template;
    
close(FILE);

    
$shell .= "zone \"$domainname\"   {type master; file \"$domainname.zone\";};\n";

    
$interface++;
    
    }

print 
$shell;
print 
"\n\n\nCopy the above commands and paste into named.conf.\n"
SplitInfinity is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote