• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

/bin

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.
Here is the complete code, with installer and icons (it even sets up a desktop icon)

EDIT: found a problem in the setup file, fixed and re-upped the package
 

Attachments

  • aptitude_program.7z
    90.6 KB · Views: 97
Last edited:
This is a script to assist in the generation of structure files for the OpenEdge database

Code:
#!/usr/bin/python
#As set out by progress the format for a structure file is the following:
"""
#
b <location of bi file>.b1 
#
d "Schema Area":6,32;1 <location of schema area>.d1
#
d <Area Name>:<Area Number>,<records per block>;<blocks per cluster> <location of extent>/<database name>_<area number>.d1 f <extent size>
"""
#This script will interactively generate a structure file and the use progress tools to install them
#It relies heavily on while-loops for sanity checking. 

import sys
import os


###########################################################
#Testing to make sure that user inputs the correct answers#
###########################################################
def sanity_check_expect_string(prompt_user, error_message):
    acceptable_input_flag = 0
    while acceptable_input_flag == 0:
        expecting_string = raw_input(prompt_user)
        if expecting_string != "":
                acceptable_input_flag = 1
                return expecting_string
        else:
                print error_message
                
#######################################################

def sanity_check_integer(prompt_user, error_message):
    extent_size_not_digit = 0
    acceptable_input_flag = 0
    #We want to make sure that what is being entered is a digit
    while acceptable_input_flag == 0:
        expecting_integer = raw_input(prompt_user)
        
        if expecting_integer.isdigit() == True :
                acceptable_input_flag = 1
                if prompt_user == 'Please enter the number of extents in this area: ' or prompt_user == "How many BI extents do you wish to create: ":
                    if str(expecting_integer) == "1":
                        pass
                    else:
                        extent_size = sanity_check_integer("Please enter the extent size: ", "\n!!!!you did not enter a valid extent size \n")
                        while extent_size_not_digit == 0:
                            if extent_size.isdigit() == True:
                                extent_size_not_digit = 1
                                return expecting_integer
                                return extent_size
                            else:
                                print error_message
                return expecting_integer
        else:
                print error_message
#######################################################3

#Get the database name
database_name = sanity_check_expect_string('Please enter the database name: ', "\n!!!!You left the database name blank\n")
#We need the dbms location in order to create the structure file there
dbms_location = raw_input('Please enter the full path to the dbms folder is located: ')

#here we are just removing the trailing slash for consistency throughout the script
if "dbms/" in dbms_location:
    dbms_location = dbms_location.replace("dbms/", "dbms")
    print "correcting dbms_location to ", dbms_location

#make sure that the user is actually entering a dbms location
while "/dbms" not in dbms_location:
    print "\n!!!!The /dbms folder not specified\n"
    dbms_location = raw_input('Please enter the full path to the dbms folder is located: ')


#set the absolute path for the structure file
try:
    structure_file_abs_path = dbms_location, "/", database_name, ".st"
    structure_file_abs_path = "".join(structure_file_abs_path)

    #Open the structure file for writing  
    structure_file = open('%s' % structure_file_abs_path, 'w')  
except:
    print "The location you specified does not exist ", "(", dbms_location, ")"      
    sys.exit()

database_block_size = raw_input('Enter the block size to use for the database (default: 8192): ')

#This sets the default block size to 8k
if database_block_size == "":
    database_block_size = 8192
    print "\nblocksize is ", database_block_size, "\n"


#convert the raw input into an integer for testing

database_block_size = int(database_block_size)
#This section determines which 'empty' database openEdge will use
#We set the flag in order to make sure that a correct block size gets entered
#If a correct size is entered and the flag gets changed to 1 breaking the loop
flag = 0
while flag == 0:
    if database_block_size == 8192:
        empty_database = "empty8"
        flag = 1
    elif database_block_size == 4096:
        empty_database = "empty4"
        flag = 1
    elif database_block_size == 2048:
        empty_database = "empty2"
        flag = 1
    elif database_block_size == 16384:
        empty_database = "empty16"
        flag = 1
    elif database_block_size == 1024:
        empty_database = "empty1"
        flag = 1
    else:
        if database_block_size == "":
            database_block_size = 8192
            empty_database = "empty8"
            flag = 1
        else:
            print "\nYou did not enter a valid block size!"
            database_block_size = raw_input('Enter the block size to use for the database: ')
            database_block_size = int(database_block_size)

################################BI area#######################
#Set the BI areas
number_of_bi_areas = sanity_check_integer("How many BI extents do you wish to create: ", "\n!!!!You did not enter a valid number of areas to create \n")

counter = 0
structure_file.write("#\n")
while counter < (int(number_of_bi_areas)) :
        structure_file.write('b %s/%s.b%s \n' % (dbms_location, database_name, (counter + 1)))
        counter +=1

#print the schema info which we want to always be the same
structure_file.write("#\n")
structure_file.write('d "Schema Area":6,32;1 %s/%s.d1 \n' % (dbms_location, database_name))


#This sanity check makes sure that the number of areas to create is an actual number
number_of_areas = sanity_check_integer("Enter the number of areas to create: ", "\n!!!!You did not enter a valid number of areas to create \n")
#######################Generation of the individual extent areas loop ###################
#get the name of the area
area_number = 0
while area_number < int(number_of_areas):
    #Get the name of the area
    area_name = sanity_check_expect_string('\nPlease enter the name of the area: ', "\n!!!!you did not enter a valid area name \n")
    
    #get the number of extents
    number_of_extents = sanity_check_integer('Please enter the number of extents in this area: ', "\n!!!!you did not enter a valid number of extents\n")
    
    
    
    #get the records per block, usually indexes are 1 record per block. Data can vary
    records_per_block = sanity_check_integer('How many records per block? ', "\n!!!!you did not enter a valid number of records per block \n")
    
    #Get the number of blocks per cluster. For indexes there are usually 8 blocks per cluster, again data can vary
    blocks_per_cluster = sanity_check_integer('How many blocks per cluser? ', "\n!!!!you did not enter a valid number of blocks per cluster \n")
    
    #get the extent location
    extent_location = dbms_location, "/", database_name, "_%s" % (area_number + 7),  ".d%s" % (number_of_extents)
    extent_location = "".join(extent_location)
    counter = 0
    structure_file.write("\n#\n")
    
    #this prints the required number of extents -1. This assumes the last extent is going to be variable
    while counter < (int(number_of_extents) - 1) :
        structure_file.write('d "%s":%s,%s;%s %s f %s \n' % (area_name, (area_number + 7), records_per_block, blocks_per_cluster, extent_location, extent_size))
        counter +=1
    structure_file.write('d "%s":%s,%s;%s %s' % (area_name, (area_number + 7), records_per_block, blocks_per_cluster, extent_location))
    area_number += 1

###############################End invidiual area extent generation ########################

print " "
#set the location of the database, which joins the dbms location with the database to create an absolute path to the database
database_location = dbms_location, "/", database_name
database_location = "".join(database_location)

#make sure that the file to parse exists in the CWD
if os.path.exists("create_blank_response.py") == True:

    #we are assuming that the structure file builder is located in the same directory as the create_blacnk_response.py
    #in order to grab the DLC  
    for line in open("create_blank_response.py", "r"):
        if "path=" in line and "workpath=" not in line and "oem_path=" not in line and "oem_workpath=" not in line and "jdkHomePath" not in line and "esbpath=" not in line:
            dlc_path = line.replace("path=", "")
        else:
            pass
    #Locate the empty database file
    empty_path = dlc_path.rstrip() + "/" + empty_database
    #empty_path = "".join(empty_path)
    print empty_database
    print "The current DLC path is: ", dlc_path
    print "The empty database is located ", empty_path

else:
    print "Could not get the DLC from create_blank_response.py... is it located in the current working directory"
    print "Aborting installation process. The structure file was created at: ", structure_file_abs_path
    sys.exit()
    
#Close the structure file so that there can be no more writing
structure_file.close()

#Print the contents of the structure file for verification in read only mode
structure_file = open('%s' % structure_file_abs_path).readlines()

for line in structure_file:
    print line,

#ask the user if they want to install the current structure file
install = raw_input('\nDo you wish to install with these settings (y/n)? ')

if install == "y" or install == "Y":
    #create the database with a specified block size
    os.chdir(dbms_location)
    os.system("prostrct create %s %s.st -blocksize %s" % (database_location, database_name, database_block_size))
    os.system("procopy %s %s" % (empty_path, database_name))
else:
    print ""
    print "OK, user aborted the installation"
    print "The structure file is located at: ", structure_file_abs_path
 
Last edited:
This is a different version of the nmap program. It parses the aggressive nmap scan

Code:
#!/usr/bin/python

import re
import os
import sys
import MySQLdb
from BeautifulSoup import BeautifulSoup, NavigableString

last_line = '---'  #if you reach this line, treat previous lines as a single block
scratch_file = "sit_new"

database_connection = MySQLdb.connect('192.168.89.22', 'root', '', 'nmap');
cursor = database_connection.cursor()

#nmap_output is the file which nmap will be piped to
nmap_output = "SIT_nmap_aggressive"
##########################################################################
def createNmap():
    
    
    #Run the nmap command with the option to querry the host OS
    #os.system("sudo nmap -O 192.168.88.0/24 > '%s'" % str(nmap_output))    
    nmap_unformatted = open(nmap_output, "r").readlines()
    #Words to exclude
    word1 = "up"
    word3 = "Starting"
    word4 = "done"
    word5 = "Not"
    word6 = "MAC"
    word7 = "Device"
    word8 = "Network"
    word9 = "detection"

#Here I am redirecting standard out to the scratch file
#So that the info can be more easily managed
    old_stdout = sys.stdout
    sys.stdout = open(scratch_file, "w")
    for line in nmap_unformatted:
        if word1 not in line and word3 not in line and word5 not in line and word6 not in line and word7 not in line and word8 not in line and word9 not in line:
     #replace the blank lines with dashes so that they are easier to parse
            if line.isspace():
                print "---"
            else:
                print line.strip()
    #Put the stardard out back to normal
    sys.stdout = old_stdout
##########################################################################  
def parse_ports():


    
        ###############Parse known ports from the IANA list ####################
    #open the xml file for reading
    ports_xml = open("port_numbers.xml", "r")
    search_xml = BeautifulSoup(ports_xml) 

    #This tells beautiful soup to pull out only the name tag 
    search_unassigned_numbers = search_xml.findAll('record')
    #The file contains stuff we dont want (unassined and reserved ports)
    #This list contains the known ports that we want
    filtered_entries = []

    #append the appropriate ports to the filtered_entries list
    for entries in search_unassigned_numbers:
        entries = str(entries)
        if "Unassigned" in entries or "Reserved" in entries:
            pass
        else:
            filtered_entries.append(entries)

    #Turn the list into text so that Beautiful soup can use it
    filtered_entries = "".join([x for x in filtered_entries])

    #Change the soup tags so that it is searching the filtered entries
    search_xml = BeautifulSoup(filtered_entries)
    search_port = search_xml.findAll('record')

    #set the list for the port_descriptions
    port_description = []


    port_names = re.compile(r'<name>.*</name>')
    counter = 0
    #while counter < len(port_number):
    for ports in search_port:
        ports = str(ports)
        find_ports = port_names.findall(ports)    
        find_ports = " ".join(find_ports)
        if "name" in find_ports:

            find_ports = find_ports.replace("<name>", "").replace("</name>", "")
            #print find_ports
            port_description.append(find_ports)
        else:
            port_description.append("")
        
    #set the list for the port numbers
    port_number = []
    port_names = re.compile(r'<number>.*</number>')
    counter = 0
    for ports in search_port:
        ports = str(ports)
        find_ports = port_names.findall(ports)    
        find_ports = " ".join(find_ports)
        if "number" in find_ports:
            #remove the tags and leave only the port numbers going into the list
            find_ports = find_ports.replace("<number>", "").replace("</number>", "")
            #print find_ports
            port_number.append(find_ports)
        else:
            port_number.append("") 


    protocol_name = []

    protocol_names = re.compile(r'<protocol>.*</protocol>')
    counter = 0
    for protocol in search_port:
        ports = str(ports)
        find_ports = port_names.findall(ports)    
        find_ports = " ".join(find_ports)
        if "protocol" in find_ports:
        #remove the tags and leave only the protocol names going into the list

            find_ports = find_ports.replace("<protocol>", "").replace("</protocol>", "")
            protocol_name.append(find_ports)
        else:
            protocol_name.append("")

        #############Begin parsing nmap###################
    port_list = []
    nmap_file = open(nmap_output).readlines()
    flag = 0
    for line in nmap_file:
        if line.startswith('Nmap'):
            flag = 0
        if last_line in line:
            flag = 1
        if not flag and not last_line in line:
            #append the line to the list and strip the dashes away
            port_list.append(line.strip('---').rstrip())
    
    #set the computer_id to 0. The computer_id represents the ID of the computer
    #each port can have the same ID. In this way ports 80, 22, 443 etc all reference computer by ID
    computer_id = 0
    existing_ports = []
    for ports_open in port_list:
        starts_with_digit = re.match(r"[0-9]", ports_open) is not None
        #For the ports section we dont want anything that starts with a letter
        #If the line starts with a digit, parse out only the port number
        if starts_with_digit == True:
            ports_open = ports_open.split('/')[0]
            #print "Inserting: ", ports_open
            existing_ports.append(ports_open)
            cursor.execute("INSERT ignore INTO Ports_Table(Port_ID, Open_Port) values('%s','%s')" % (computer_id, ports_open))
            print "INSERT ignore INTO Ports_Table(Port_ID, Open_Port) values('%s','%s')" % (computer_id, ports_open)
            continue
        #If the line starts with Port, increase the computer_id. Nmap lists the PORT heading only once per computer
        #Therefore it is a reliable way to indicate the ID of a new computer
        elif starts_with_digit == False and "Nmap" in ports_open:
            computer_id +=1
        elif "All 1000" in ports_open:
            print "no ports open at ID ", computer_id
            ports_open = 0
            cursor.execute("INSERT ignore INTO Ports_Table(Port_ID, Open_Port) values('%s','%s')" % (computer_id, ports_open))
    #Loop through the open ports on your network and only add port descriptions of ports which exist on your network
    #This was done to reduce querry time against the list of known ports
    x = 0
    while x < len(port_number):
        if port_number[x] in existing_ports:
            print "adding ", port_number[x], port_description[x], protocol_name[x], " to the database"
            cursor.execute("INSERT ignore INTO Port_Description(Port_Number, Port_Description, Port_Protocol) values('%s', '%s', '%s')" % (port_number[x], port_description[x], protocol_name[x]))
        else:
            print "This port is not found among the open ports on your network.... OMITTING"
        x +=1
#######################################################################   
def parse_dns():
    #to parse the aggress nmap it seems to be required to reset the last line parameter
    sit_nmap = open("SIT_nmap_aggressive").readlines()
    last_line = "HOP RT"
    os_list = []
    flag = 0

    #purge the stuff we dont want in the file
    for line in sit_nmap:
            if line.startswith('Nmap scan'):
                flag = 0
            if last_line in line:
                flag = 1
            if not flag and not last_line in line:
                #append the line to the list and strip the dashes away
                if "SF:" in line or "SF-" in line:
                    pass
                elif "OS: " in line:
                    os_list.append(line)
                elif "tcp" in line:
                    pass
                elif "====" in line:
                    pass
                elif "OS:" in line:
                    pass
                elif "|_" in line and not "NetBIOS" in line:
                    pass
                
                else:
                    os_list.append(line.rstrip())

    number_of_hosts = 0
    newstring = []
    #Pull out all of the netbios names to circumvent the dns since SIT does not keep Linux machines up to date in the dns
    for x in os_list:
        if "Nmap scan" in x:
            number_of_hosts +=1
        netbios = re.findall(r"NetBIOS name.*, ", x)
        netbios = "".join(netbios)

        if netbios == "":
            pass
        #in order to determine which computer the netbios name goes with, we insert the number in order to split it off later for insertion
        else:
            netbios = netbios.split(" ")
            netbios = netbios[2].replace(",", "")
            netbios = netbios, number_of_hosts
            netbios = "".join(str(netbios))
            newstring.append(netbios)
        
    #In order to work around a parsing problem we insert blank entries
    ID = 1
    while ID < number_of_hosts:
        cursor.execute("INSERT INTO Computer_Info(Computer_ID,DNS_Name) values('%s', '')" % ID)
        cursor.execute("INSERT ignore INTO Computer_Ports(Computer_ID, Port_ID) values('%s', '%s')" % (ID, ID))
        ID +=1

    #The new string is mostly a dumby list to simply allow the computer name to be matched with the proper id
    #There probably is a better way to do this...
    for x in newstring:
        x = x.split(" ")
        name = x[0].replace("('", "").replace("',", "")
        ID = x[1].replace("'", "").replace(")", "")
        cursor.execute("UPDATE Computer_Info SET `DNS_Name`='%s' WHERE `Computer_ID`='%s'" % (name, ID))

    #The counter keeps track of which host we are looping through
    counter = 1
    for ip_address in os_list:
            if ip_address.startswith('Nmap scan'):
                    flag = 0
            if last_line in ip_address:
                    flag = 1
                
            if "scan report" in ip_address:
                    ip = re.compile(r'192.\d+.\d+.\d+')
                    find_ip = ip.findall(ip_address)
                    find_ip = str(find_ip).replace("['", "").replace("']", "")
                    cursor.execute("UPDATE Computer_Info SET `Computer_IP_Address`='%s', `OS_ID`='%s' WHERE `Computer_ID`='%s'" % (find_ip, counter, counter))
                    counter +=1
                    
#######################################################                   
def parse_os():
    sit_nmap = open("SIT_nmap_aggressive").readlines()
    last_line = "HOP RT"
    os_list = []
    flag = 0

    for line in sit_nmap:
            starts_with_digit = re.match(r"[0-9]", line) is not None
            if line.startswith('Nmap scan'):
                flag = 0
            if last_line in line:
                flag = 1
            if not flag and not last_line in line:
                #append the line to the list and strip the dashes away
                if starts_with_digit == True:
                    pass
                elif "SF:" in line or "SF-" in line:
                    pass
                
                elif "tcp" in line:
                    pass
                elif "====" in line:
                    pass
                
                elif "|_" in line and not "NetBIOS" in line:
                    pass
                
                elif "OS: " in line:
                    os_list.append(line)
                else:
                    os_list.append(line.rstrip())
    newstring = []
    counter = 1

    #for my own tracking I am keeping a seperate list for Linux, Windows and other
    microsoft = []
    linux = []
    other = []
    computer_id = 0
    for host_os in os_list:
        #skip over the open ports as they are the only lines that start with digits
        starts_with_digit = re.match(r"[0-9]", host_os) is not None
        if "Nmap scan" in host_os:
            computer_id +=1
            
        if starts_with_digit == True:
            pass
        
        #As with before I append the computer number in order to line the OS with the appropriate computer_id
        elif "|   OS: Windows" in host_os:
            host_os = host_os.split(":")
            host_os = host_os[1].split("(")
            host_os = host_os[0].replace("[' ", "")
            host_os = computer_id, host_os
            host_os = "".join(str(host_os))
            microsoft.append(host_os.rstrip())
            
        elif "OS details: Linux" in host_os:
            host_os = host_os.strip("OS details: ")
            host_os = computer_id, host_os.rstrip()
            host_os = "".join(str(host_os))
            linux.append(host_os)
        elif "OS details:" in host_os and "Microsoft" not in host_os and "Linux" not in host_os:
            host_os = host_os.strip("OS details: ")
            host_os = computer_id, host_os.rstrip()
            host_os = "".join(str(host_os))
            other.append(host_os)
        elif "No exact" in host_os:
            host_os = computer_id, "Not Available"
            host_os = "".join(str(host_os))
            other.append(host_os)
        elif "Too many" in host_os:
            host_os = computer_id, "Not Available"
            host_os = "".join(str(host_os))
            other.append(host_os)
    counter = 1
    ips = []
    for x in os_list:
            if x.startswith('Nmap scan'):
                    flag = 0
            if last_line in x:
                    flag = 1
                
            if "scan report" in x:
                    ip = re.compile(r'192.\d+.\d+.\d+')
                    find_ip = ip.findall(x)
                    find_ip = str(find_ip).replace("['", "").replace("']", "")
                    counter +=1
                    ips.append(find_ip)

    #set the OS_ID, by setting the id but the OS_name blank at first
    loop = 1
    while loop < computer_id:
        cursor.execute("INSERT into OS_Table (OS_ID) values('%s')" % (loop))
        loop += 1
    
    #Insert the Operating systems into the OS_Name
    for x in microsoft:
       x = x.split(",")
       ID = x[0].replace("(", "")
       os = x[1].replace("'", "").replace(")", "").rstrip()
       cursor.execute("UPDATE Computer_Info SET `OS_ID`='%s' WHERE `Computer_ID`='%s'" % (ID, ID))
       cursor.execute("UPDATE OS_Table SET `OS_Name`='%s' WHERE `OS_ID`='%s'" % (os, ID))
       
    for x in linux:
        x = x.split(",")
        ID = x[0].replace("(", "")
        os = x[1].replace("'", "").replace(")", "").rstrip()
        cursor.execute("UPDATE Computer_Info SET `OS_ID`='%s' WHERE `Computer_ID`='%s'" % (ID, ID))
        cursor.execute("UPDATE OS_Table SET `OS_Name`='%s' WHERE `OS_ID`='%s'" % (os, ID))

    for x in other:
        x = x.split(",")
        ID = x[0].replace("(", "")
        os = x[1].replace("'", "").replace(")", "").rstrip()
        cursor.execute("UPDATE Computer_Info SET `OS_ID`='%s' WHERE `Computer_ID`='%s'" % (ID, ID))
        cursor.execute("UPDATE OS_Table SET `OS_Name`='%s' WHERE `OS_ID`='%s'" % (os, ID))
##################################################

parse_ports()
parse_dns()
parse_os()


and the ui is basically the same with a few behind the scenes tweaks


Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pygtk
import gtk
import os
import sys
import MySQLdb

database_connection = MySQLdb.connect('localhost', 'root', '', 'nmap');
cursor = database_connection.cursor()

class Application(gtk.Window):
    cells = {}
    columns = {}
    sort_order = gtk.SORT_ASCENDING
####################
    def __init__(self):
        gtk.Window.__init__( self )
        self.set_title("Netowrk Scanner")
        self.set_position(gtk.WIN_POS_CENTER)
        self.create_widgets()
        self.connect_signals()

        #self.window.show_all()
        self.show_all()
        gtk.main()
##################        
    def create_widgets(self):
        #Ask the user to search by operating system
        self.vbox = gtk.VBox(spacing=10)
        self.operating_system_label_hbox_1 = gtk.HBox(spacing=10)
        self.label = gtk.Label("Search by Operating System :")
        self.operating_system_label_hbox_1.pack_start(self.label)

        #Set a check box so the user can choose to display ports
        self.ports_hbox_8 = gtk.HBox(spacing=10)
        self.ports_check = gtk.CheckButton("Display Ports")
        self.ports_hbox_8.pack_start(self.ports_check)
        self.halign_ports = gtk.Alignment(0,1,1,0)
        self.halign_ports.add(self.ports_hbox_8)

        self.os_entry_hbox_2 = gtk.HBox(spacing=10)
        self.OS = gtk.Entry()
        self.os_entry_hbox_2.pack_start(self.OS)

        self.hostname_label_hbox_3 = gtk.HBox(spacing=10)
        self.label = gtk.Label("Search by Hostname:")
        self.hostname_label_hbox_3.pack_start(self.label)

        self.hostname_entry_hbox_4 = gtk.HBox(spacing=10)
        self.HOSTNAME = gtk.Entry()
        self.hostname_entry_hbox_4.pack_start(self.HOSTNAME)

        self.ip_label_hbox_5 = gtk.HBox(spacing=10)
        self.label = gtk.Label("Search by IP:")
        self.ip_label_hbox_5.pack_start(self.label)

        self.ip_entry_hbox_6 = gtk.HBox(spacing=10)
        self.IP = gtk.Entry()
        self.ip_entry_hbox_6.pack_start(self.IP)

        self.buttons_hbox_7 = gtk.HBox(spacing=10)
        self.button_ok = gtk.Button("Get Results!")
        self.buttons_hbox_7.pack_start(self.button_ok)
        self.button_exit = gtk.Button("Get me Outta Here!")
        self.buttons_hbox_7.pack_start(self.button_exit)

        #The order in which you pack_start a widget is the order in which it is displayed on the screen
        self.vbox.pack_start(self.operating_system_label_hbox_1)
        self.vbox.pack_start(self.os_entry_hbox_2)
        self.vbox.pack_start(self.hostname_label_hbox_3)
        self.vbox.pack_start(self.hostname_entry_hbox_4)
        self.vbox.pack_start(self.ip_label_hbox_5)
        self.vbox.pack_start(self.ip_entry_hbox_6)
        self.vbox.pack_start(self.halign_ports, False, False, 3)
        self.vbox.pack_start(self.buttons_hbox_7)

        self.add(self.vbox)
##########################
    def connect_signals(self):
        #Have the buttons start 'listening' for user interaction
        self.button_ok.connect("clicked", self.button_click)
        self.button_exit.connect("clicked", self.exit_program)
########################
    def button_click(self, clicked):
        #This function gets the values of the input boxes as well as the check box
        #And then passes them to the show_table function so it can get the correct results from the database
        global ports_check, os, ip, hostname
        os = self.OS.get_text()
        ip = self.IP.get_text()
        hostname = self.HOSTNAME.get_text()
        ports_check = self.ports_check.get_active()
        
        if os == "" and ip == "" and hostname == "":
            error_message = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "You haven't entered anything to search for!")
            error_message.run()
            error_message.destroy()
        else:
            if hostname != "" and (os != "" or ip != ""):
                error_message = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "If you know the hostname why are you searching with other options? Please search by hostname only")
                error_message.run()
                error_message.destroy()
                self.OS.set_text("")
                self.IP.set_text("")
                self.HOSTNAME.set_text("")
            else:
                self.show_Table(os, ip, hostname)
##############        
    def show_Table(self, search_os, search_ip, search_hostname):
    ### Create the table
        # List of items to display which represent IP, OS, DNS, Port number and Port description
         # Columns
        if ports_check == True:
            cols = ['IP Address', 'Operating System', 'Hostname', 'Ports', 'Protocol Name']
        else:
            cols = ['IP Address', 'Operating System', 'Hostname']
        """    
        self.newColumn("IP Address", 0)
        self.newColumn("Operating System", 1)
        self.newColumn("Hostname",2)
        #I only want the ports columns to show if the user requests it because this calls different mysql querries
        if ports_check == True:
            self.newColumn("Ports", 3)
            self.newColumn("Protocol name", 4)
        """
        
        sequence = [str] * len(cols)
        self.treestore = gtk.TreeStore( * sequence)
        self.treestore.connect("rows-reordered", self.on_column_clicked)
        self.treeview = gtk.TreeView(self.treestore)
        self.treeview.cell = [None] * len(cols)
        self.treeview_column = [None] * len(cols)
        
        for column_number, col in enumerate(cols):
            self.treeview.cell[column_number] = gtk.CellRendererText()
            self.treeview_column[column_number] = gtk.TreeViewColumn(col, self.treeview.cell[column_number])
            self.treeview_column[column_number].add_attribute(self.treeview.cell[column_number], 'text', column_number)
            self.treeview_column[column_number].set_resizable(True)
            self.treeview_column[column_number].set_reorderable(True)
            self.treeview_column[column_number].set_sort_indicator(True)
            self.treeview_column[column_number].set_sort_column_id(column_number)
            self.treeview.append_column(self.treeview_column[column_number])
        
        self.scrollTree = gtk.ScrolledWindow()
        self.scrollTree.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        self.scrollTree.add(self.treeview)
        
        #If the user is running a search on the hostname run these querries
        if search_hostname != "":
            if ports_check == True:
                    cursor.execute("SELECT DISTINCT Computer_IP_Address, OS_Name, DNS_Name, Port_Description, Open_Port FROM Computer_Ports AS CP \
                        JOIN Computer_Info AS CI ON ( CP.Computer_ID = CI.Computer_ID ) \
                        JOIN Ports_Table AS PT ON ( CP.Port_ID = PT.Port_ID ) \
                        JOIN OS_Table AS OS ON ( CI.Computer_ID = OS.OS_ID ) \
                        JOIN Port_Description AS PS ON ( PT.Open_Port = PS.Port_Number ) \
                        WHERE DNS_Name LIKE '%%%s%%' ORDER BY inet_aton( Computer_IP_Address ), Open_Port" % (search_hostname))
            #Otherwise just return the relevent data
            else:
                    cursor.execute("SELECT DISTINCT Computer_IP_Address, OS_Name, DNS_Name FROM Computer_Info AS CI  \
                        JOIN OS_Table AS OS ON ( CI.Computer_ID = OS.OS_ID ) \
                        WHERE DNS_Name LIKE '%%%s%%' ORDER BY inet_aton( Computer_IP_Address )" % (search_hostname))
        
        
        #If the user has specified the IP and the OS to search, run this querry  
        if search_os != "" and search_ip !="":
        #Set up the querries. If the user has activted the checkbox, we need to include the ports in the querry
            if ports_check == True:
                 cursor.execute("SELECT DISTINCT Computer_IP_Address, OS_Name, DNS_Name, Port_Description, Open_Port FROM Computer_Ports AS CP \
                    JOIN Computer_Info AS CI ON ( CP.Computer_ID = CI.Computer_ID ) \
                    JOIN Ports_Table AS PT ON ( CP.Port_ID = PT.Port_ID ) \
                    JOIN OS_Table AS OS ON ( CI.Computer_ID = OS.OS_ID ) \
                    JOIN Port_Description AS PS ON ( PT.Open_Port = PS.Port_Number ) \
                    WHERE OS_Name LIKE '%%%s%%' and Computer_IP_Address LIKE '%%%s%%' ORDER BY inet_aton( Computer_IP_Address ), Open_Port" % (search_os, search_ip))
        #Otherwise just return the relevent data
            else:
                cursor.execute("SELECT DISTINCT Computer_IP_Address, OS_Name, DNS_Name FROM Computer_Info AS CI ON  \
                    JOIN OS_Table AS OS ON ( CI.Computer_ID = OS.OS_ID ) \
                    WHERE OS_Name LIKE '%%%s%%' and Computer_IP_Address LIKE '%%%s%%' ORDER BY inet_aton( Computer_IP_Address )" % (search_os, search_ip))
        #If the user has specified an OS but not an IP run this
        elif search_os != "" and search_ip == "":
            if ports_check == True:
                 cursor.execute("SELECT DISTINCT Computer_IP_Address, OS_Name, DNS_Name, Port_Description, Open_Port FROM Computer_Ports AS CP \
                    JOIN Computer_Info AS CI ON ( CP.Computer_ID = CI.Computer_ID ) \
                    JOIN Ports_Table AS PT ON ( CP.Port_ID = PT.Port_ID ) \
                    JOIN OS_Table AS OS ON ( CI.Computer_ID = OS.OS_ID ) \
                    JOIN Port_Description AS PS ON ( PT.Open_Port = PS.Port_Number ) \
                    WHERE OS_Name LIKE '%%%s%%' ORDER BY inet_aton( Computer_IP_Address ), Open_Port" % search_os)
            else:
                cursor.execute("SELECT DISTINCT Computer_IP_Address, OS_Name, DNS_Name FROM Computer_Info AS CI \
                    JOIN OS_Table AS OS ON ( CI.Computer_ID = OS.OS_ID ) \
                    WHERE OS_Name LIKE '%%%s%%' ORDER BY inet_aton( Computer_IP_Address )" % search_os)
        #If the user has specified an IP but not an OS run this
        elif search_os =="" and search_ip != "":
            if ports_check == True:
                cursor.execute("SELECT DISTINCT Computer_IP_Address, OS_Name, DNS_Name, Port_Description, Open_Port FROM Computer_Ports AS CP \
                    JOIN Computer_Info AS CI ON ( CP.Computer_ID = CI.Computer_ID ) \
                    JOIN Ports_Table AS PT ON ( CP.Port_ID = PT.Port_ID ) \
                    JOIN OS_Table AS OS ON ( CI.Computer_ID = OS.OS_ID ) \
                    JOIN Port_Description AS PS ON ( PT.Open_Port = PS.Port_Number ) \
                    WHERE Computer_IP_Address LIKE '%%%s%%' ORDER BY inet_aton( Computer_IP_Address ), Open_Port" % search_ip)
            else:
                 cursor.execute("SELECT DISTINCT Computer_IP_Address, OS_Name, DNS_Name FROM Computer_Info AS CI \
                    JOIN OS_Table AS OS ON ( CI.Computer_ID = OS.OS_ID ) \
                    WHERE Computer_IP_Address LIKE '%%%s%%' ORDER BY inet_aton( Computer_IP_Address )" % search_ip)

        #get the results and prepare to put them inside of lists
        fetch_results = cursor.fetchall()
        host_name_list = []
        operating_list = []
        ip_list = []
        ports = []
        #The element chosen to append to each list based on the order of retrieval in the mysql querry
        for individual_result in fetch_results:
            ip_list.append(individual_result[0])
            operating_list.append(individual_result[1])    
            host_name_list.append(individual_result[2])
            if ports_check == True:    
                ports.append(individual_result[3])
        #we are going to add blanks to the files in order to help readability
        #when putting this into the chart
        cleaned_host =[]
        cleaned_ip = []
        cleaned_os_list = []

        index_counter = 0
        #this loop will check to see if the entry already exists in the cleaned variables. If it does, it 'omitts' them by inserting a blank line
        while index_counter < len(host_name_list):
            if host_name_list[index_counter] in cleaned_host:
              #print "found a duplicate in HOST....OMITTING"
              cleaned_host.append("")
            else:
                #print "adding ", host_name_list[index_counter]  
                cleaned_host.append(host_name_list[index_counter])

            if operating_list[index_counter] in cleaned_os_list and ip_list[index_counter] in cleaned_ip:
                #print "found a duplicate in OPERATING....OMITTING"
                cleaned_os_list.append("")
            else:
                #print "adding ", operating_list[index_counter]     
                cleaned_os_list.append(operating_list[index_counter])

            if ip_list[index_counter] in cleaned_ip:
                #print "Found a duplicate in IP.... OMITTING "
                cleaned_ip.append("")
            else:
                #print "adding ", ip_list[index_counter]     
                cleaned_ip.append(ip_list[index_counter])
            index_counter +=1  

        #this section appends to the list store depending on whether the user wants to see the ports or not
        counter = 0
        for single_result in fetch_results:
            if ports_check == True:
                self.treestore.append( None,
            [ cleaned_ip[counter], cleaned_os_list[counter], cleaned_host[counter], single_result[4], single_result[3] ]
            )

            else:

                self.treestore.append(None,
            [ single_result[0], single_result[1], single_result[2] ]
            )
            counter +=1
        
        
        self.frm_table = gtk.Window()
        self.frm_table.set_default_size(600, 800)
        self.frm_table.set_title("Network scan results")
        #Change the background to white instead of grey
        self.frm_table.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#fff'))
        self.frm_table.add(self.scrollTree)
        self.frm_table.show_all()
###################### 
    def on_column_clicked(self, col1, col2, col3, col4 ):
        #This function allows the columns to be resorted upon click

        if self.sort_order == gtk.SORT_ASCENDING:
            self.sort_order = gtk.SORT_DESCENDING
        else:
            self.sort_order = gtk.SORT_ASCENDING

        #tc.set_sort_order(self.sort_order) 
###############        
    def exit_program(self, widget, callback_data=None):
        gtk.main_quit()
#---------------------------------------------
if __name__ == "__main__":
    app = Application() 
    database_connection.commit()
    cursor.close()
    database_connection.close()
 
A little bash script I use to download hourly Folding@Home stats for top 20 teams and team 32 users:

Code:
#!/bin/bash

x=$(date +%Y-%m-%d_%H)

wget http://fah-web.stanford.edu/daily_team_summary.txt.bz2 -O /home/petteyg/folding/team-${x}.txt.bz2
bzip2 -d /home/petteyg/folding/team-${x}.txt.bz2
mv /home/petteyg/folding/team-${x}.txt /home/petteyg/folding/team-${x}.txt.orig
head -n23 /home/petteyg/folding/team-${x}.txt.orig | tail -n20 > /home/petteyg/folding/team-${x}.txt
rm /home/petteyg/folding/team-${x}.txt.orig
bzip2 -9 /home/petteyg/folding/team-${x}.txt

wget http://fah-web.stanford.edu/daily_user_summary.txt.bz2 -O /home/petteyg/folding/user-${x}.txt.bz2
bzip2 -d /home/petteyg/folding/user-${x}.txt.bz2
mv /home/petteyg/folding/user-${x}.txt /home/petteyg/folding/user-${x}.txt.orig
grep -P "\s32$" /home/petteyg/folding/user-${x}.txt.orig > /home/petteyg/folding/user-${x}.txt
rm /home/petteyg/folding/user-${x}.txt.orig
bzip2 -9 /home/petteyg/folding/user-${x}.txt
 
Here is a script I used to detect new leases on a dhcp3 server and add it into bind/dns
It also locks the people into the address leased so that the dns entries dont need to be altered

Code:
#!/usr/bin/python
#This script is designed to automatically update dhcp and dns as new hosts
#join the network. The danger in this script is having too many hosts joining the network without
import os
import sys
import time
import fileinput 
import datetime

#The date is important to increment the serial in bind
#it takes the format year, month, day, minute (in case there are multiple edits in one day)
date = datetime.datetime.now().strftime("%Y%m%d%M")
dhcp_lease_file = "/var/lib/dhcp/dhcpd.leases"
dhcp_conf = "/etc/dhcp/dhcpd.conf"
dns_zone = "/etc/bind/zones/stratus-sphere.com.db"
#use os.stat is used to determine if the file has changed
watch = os.stat(dhcp_lease_file)

#set the current file and the last modified date to the modified time of the file to be watched
current_file = last_modified = watch.st_mtime
#create a temp file so that we are only capturing the last entry in the leases file
os.system("> /tmp/dhcp.tmp")

#create an infinite loop for monitoring the file
while 1:
    host = ""
    ip = ""
    mac = ""
    number_of_hosts = 0
    
    #if the current time is less than the last modified, assume that the file has changed
    if current_file > last_modified:
        dhcp_lease = os.popen("tail -n 9 %s > /tmp/dhcp.tmp" % dhcp_lease_file).read()
        last_modified = current_file
        
        #loop through the temp file and parse out the proper host info        
        for line in open("/tmp/dhcp.tmp").readlines():
            #Parse out the IP
            if "lease" in line:
                ip = line.rstrip().replace("lease ", "").replace(" {", "")
            #Parse out the mac address
            if "hardware ethernet" in line:
                mac = line.replace(";", "").rstrip().replace("  ", "")
            #Set custom host name based on the mac address... mostly useful for phones
            if "78:d6:f0:d5:af:27" in line:
                host = "rosanna-phone"
            if "00:26:e8:f6:26:05" in line:
                host = "steves-phone"
            #Set the generic hostname    
            if "client-hostname" in line:
                if host != "":
                    print "already have a host name"
                else:
                    host = line.replace('client-hostname ', '').replace(';', '').replace(" ", "").replace('"', '').rstrip()
        print "the current host is %s" % host
        #Check to see if the host already exists in the dns
        #if not we add the host
        if host not in os.popen("cat %s" % dns_zone).read():
            print "%s is not in the dns...adding" % host
            print "%s IN A    %s" % (host, ip)
            dns_file = open(dns_zone, "a")
            dns_file.write("%s IN A    %s\n" % (host, ip))
            dns_file.close()
            
            #increment the Serial for bind
            for line in fileinput.FileInput(dns_zone, inplace = 1):
                if "Serial"  in line:
                    line = "			 %s	; Serial\n" % date
                    print line,
                else:
                    print line,
            #get rid of the closing brack in the dhcp conf so that we can append to the file later        
            for line in fileinput.FileInput(dhcp_conf, inplace = 1):
                if "	}" in line:
                    print line,
                elif "}" in line:
                    pass
                else:
                    print line, 
            dhcp_file = open(dhcp_conf, "a")
            dhcp_file.write("	host %s {\n" % host)
            dhcp_file.write("	%s;\n" % mac)
            dhcp_file.write("	fixed-address %s;\n" % ip)
            dhcp_file.write("	}\n")
            dhcp_file.write("}")
            dhcp_file.close()
                    #Restart the DNS so that the changes take effect
            print "\nrestarting DNS"
            os.system("/etc/init.d/bind9 restart")
            time.sleep(5)
        else:
           print "found host"
    print ""
    watch = os.stat(dhcp_lease_file)
    current_file = watch.st_mtime
    time.sleep(1)
 
m3u Generator

This is a python script I have been perfecting for generating M3U playlist files given a target directory. This is the only cross platform playlist filetype where you can use it with vlc or another media player in windows or linux.

Normally I would run this once: ./generate.py -l Community/
Then I make a shortcut that does this: vlc --random Community/playlist.m3u
And then I can just double click for a random episode!

generate.py
Code:
#!/usr/bin/env python
#
# m3u Playlist Generator
# Version 1.3.7 by Teque5
# 2010.10.30-2011.11.10
#
# Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
# [url]http://creativecommons.org/licenses/by-sa/3.0/[/url]

import os
import sys
import getopt
import random
import datetime

#############################
location = '.' # Default source directory
playlistName = 'playlist' # Default playlist name
verbose = True # Shows directories being searched
relativePath = True # Produces a relative file tree from specified folder
randomize = False # Randomizes playlist output
#############################

def info():
	fileName = os.path.basename(sys.argv[0])
	print 'Usage:',fileName,'[-qrh] [-l location] [-p playlistname]\n'
	print '  -l <dir>       scanning location for playlist (default is \'.\' )'
	print '  -p <file>      set output M3U playlist name (default is \'playlist\')'
	print '  -q             run in quiet mode'
	print '  -r             randomize playlist (default is sorted)'
	print '  -h             display this help\n'
	sys.exit(1)

def createM3U():
	global playlistName
	# This puts output files in correct directories
	if location != '.': playlistName = location + playlistName
	playlistName = playlistName + '.m3u'
	extensions = ['avi','mkv','mp4','m2ts','ogm','mpg','mpeg','ogv','divx','xvid','mp3']
	home = os.path.abspath(location)
	folderName = home.split('/')
	folderName = folderName[len(folderName)-1]

	descriptor = '#EXTM3U'
	marker = '#EXTINF'
	#this is using the 'time' module (depreciated)
	#now = str(time.localtime().tm_year)+'.'+str(time.localtime().tm_mon)+'.'+str(time.localtime().tm_mday)+' '+str(time.localtime().tm_hour)+':'+ str(time.localtime().tm_min)+' PST'
	now = str(datetime.datetime.now())
	
	playlistF = file(playlistName,'w')
	playlistF.write(descriptor + '\r\n')

	#final.write(marker + ":" + str(track_length) + "," + artist + " - " + title + "\n")

	media = []
	for root, dirs, files in os.walk(home):
	  if verbose: print root # shows which directories are being indexed
	  for video in files:
		if video[len(video)-3:] in extensions:
			media.append(root + '/' + video + '\r\n')
	count = len(media)

	# Create playlists
	while len(media)!=0:
	  media.sort()
	  if randomize: i = random.randint(0,len(media)-1)
	  else: i=0
	  if relativePath: media[i] = media[i].replace(home+'/','')
	  playlistF.write(media[i])
	  media.remove(media[i])
	# Write EOF
	playlistF.write('# Generated '+ now +' PST\r\n# '+str(count) + ' items automatically randomized by Teque5\'s Playlist Generator\r\n')

	# Cleanup
	playlistF.close
	print '  Playlist generation completed.'
	if randomize: print ' ',str(count),'items randomized into',playlistName
	else: print ' ',str(count),'items sorted into',playlistName
	print '  Source directory:',home

if __name__ == '__main__':


    try:
        optlist, args = getopt.getopt(sys.argv[1:], 'qsrl:p:')
    except getopt.GetoptError, error:
        print 'Error: %s\n' % error
        info()

    for op, arg in optlist:
        if op == '-h': info()
        elif op == '-l': location = str(arg)
        elif op == '-p': playlistName = str(arg)
        elif op == '-q': verbose = False
        elif op == '-r': randomize = True

    if len(optlist) == 0: info() # comment to enable script w/o options

    # Run Main Function
    createM3U()
 
Last edited:
Code:
#!/bin/awk -f

function to_sec(date,    t) {
  split(date, t, /:/);
  return((t[1]*3600) + (t[2]*60) + t[3]);
}

function to_hr(sec,    m, s) {
  s = sec % 60;
  sec = int(sec / 60);
  m = sec % 60;
  sec = int(sec / 60);

  return(sprintf("%02d:%02d:%02d", sec, m, s));
}

function shell_quote(str) {
  gsub(/'/, "'\\''", str);

  return("'" str "'");
}

BEGIN {
  FS = "[(]|%[)][[:blank:]]*$";
}

/^\[([0-9]{2}:){2}[0-9]{2}\]/ {
  split($0, t, /[][]/);
  if ((cur = to_sec(t[2])) < lastcur) {
    day++;
    mod = day * 24 * 60 * 60;
  }
  lastcur = cur;
  time = cur + mod;
}

NF != 3 {
  next;
}

!$2 {
  wu++;
}

{
  wu = wu ? wu : 1;
  if (!(wu in start)) {
    start[wu] = $2;
    startt[wu] = time;
  }
  if ($2 == 100) {
    end[wu] = last;
    endt[wu] = time;
  }

  steps[wu,$2] = $0;
  times[wu,$2] = time;

  last = $2;
}

END {
  if (FILENAME != "-") {
    cmd = "stat -c %Y " shell_qoute(FILENAME);
    cmd | getline mtime;
    close(cmd);

    mod = (systime() - mtime);
    time = time + mod;
  }

  if (NF == 3) {
    end[wu] = last;

    for (i=start[wu]+1; i<=last; i++) {
      tot += times[wu,i] - times[wu,i-1];
    }

    printf("\nThis WU:\n");
    printf("%30s: %02d%%\n", "Current Progress", last);

    if (last > 0) {
      avg = int(tot/(last-start[wu]));
    } else {
      avg = time - startt[wu];
    }
    printf("%30s: %s\n", "AVG time per percent", to_hr(avg));

    diff = time - startt[wu];
    printf("%30s: %s\n", "Time spent on current WU", to_hr(diff));

    rem = 100 - last;
    printf("%30s: %s\n", "ETA to completion", to_hr((avg*rem)-mod));

    fin = endt[wu-1];
  } else {
    fin = endt[wu];
    printf("No WU currently in progress\n");
  }
  printf("\n");

  if (wu > 1) {
    perc = ftot = wtot = wus = 0;

    for (i=1; i<=wu; i++) {
      if (!end[i]) {
        continue;
      }
      tot = 0;

      for (j=start[i]+1; j<=end[i]; j++) {
        tot += times[i,j] - times[i,j-1];
        perc++;
      }

      wuperc = (end[i] - start[i]) / 100;
      wtot += int(tot*(1/wuperc));
      ftot += tot;
      wus++;
    }

    printf("\nAll WUs in the log:\n");

    avg = int(ftot/perc);
    printf("%30s: %s\n", "AVG time per percent", to_hr(avg));

    avg = int(wtot/wus);
    printf("%30s: %s\n", "AVG time to complete WU", to_hr(avg));

    diff = time - fin;
    printf("%30s: %s\n", "Time since last completed WU", to_hr(diff));
  } else {
    printf("No previous WUs in the log\n");
  }
  printf("\n");
}

Little script to parse FAH logs and pull out some stats. For you folders, just point it to your FAHlog.txt.

Sample output:
Code:
» check-fah FAHlog.txt

This WU:
              Current Progress: 89%
          AVG time per percent: 00:16:26
      Time spent on current WU: 24:27:07
             ETA to completion: 02:57:36


All WUs in the log:
          AVG time per percent: 00:10:52
       AVG time to complete WU: 18:13:44
  Time since last completed WU: 24:34:07

(your awk may be in /usr/bin, adjust shebang accordingly)
 
Last edited:
This is another VM backup script.

This one deals with Virtualbox

Code:
#!/usr/bin/python
#This program will first go through a cleaning process.
#It will suspend virtual machines running inside of virtualbox
#Then it will tar them, attempt to extract the tar and finally it will resume the vms and email the results
"""

Error checking is done by initializing the error variable to ""
in order to check it later. If there is an exception thrown,
the error variable gets reassigned to the thrown error
"""
import os
import sys
import time
import datetime
import fnmatch
import subprocess

########################Global Variables##########################

email_addresses = "stratus"

#Set the time variables. These will be used to determine which files to clean up
#Since time is measured in seconds, we have to do the convertion 
#The number of days held is directly related to the available storage space in /archive. If more VMs get added, 
#the number of days a file can be held will have to be decreased.
seconds_per_day = 86400
number_of_days = 12
days_to_keep_files = seconds_per_day * number_of_days
current_date = time.time()

archive_path = '/archive/vms/'

#The following creates a new directory in /archive/vms with today's date
todays_date = datetime.datetime.now().strftime("%Y-%m-%d")
todays_directory = archive_path + todays_date

logfile = "/var/log/virtual_machine_logs/vm_backup_",todays_date,".log"
logfile = "".join([str(x) for x in logfile])

old_stdout = sys.stdout
old_stderr = sys.stderr
#sys.stdout = open(logfile, "w")
#sys.stderr = open(logfile, "a")

#Initialize the error variables; blank variables mean no errors are present
error_archive = ""
error_suspend = ""
error_tar = ""
error_resume = ""
error_tar_check = ""

#Create the list of Virtual Machines
os.system("vboxmanage list runningvms > /backup_scripts/running_vms.txt")
vmlist = "/backup_scripts/running_vms.txt"  
###########################End Global Variables##########################

#Make todays backup directory

try:
    os.makedirs(todays_directory)
except:
    pass

print "---------------------Starting backup processes on this date: --------->", datetime.datetime.now().strftime("%Y-%m-%d-%H:%M"), "<----------"

#This function reads the vm list from the top. Putting this as a function avoids "cut-and-paste" programming
def read_vm_list():
    vm_list = open(vmlist, 'r')
    return vm_list

################################################cleanup section ##############################################
#This function crawls through directories as specied. It is used to recursively search
#through the directories in archive2
def find_files(directory, pattern):
    for root, dirs, files in os.walk(directory):
        for basename in files:
            #the fnmatch module is required (import fnmatch) for this section
            #after finding the file, os.path is used to create an absolute path
            #to the files. The filenames are then returned as a generator
            if fnmatch.fnmatch(basename, pattern):
                filename = os.path.join(root, basename)
                yield filename

try:
    print "The current disk usage is "
    p = os.popen('df -h |grep -v usr |grep -v tmp |grep -v udev |grep -v var |grep -v home').read()
    print p
    print "Beginning the cleaning process of /archive"
    print "Attempting to remove files from /archive which are older than ", ((days_to_keep_files + (10 * 86400))/86400), " days"

    for archive_file in find_files(archive_path, '*.gz'):
        #days_to_keep_files + 8 indicates the base number of days to keep a file in /archive and
        #The additional number of days it will be kept in /archive2
        if os.stat(archive_file).st_ctime < current_date - (days_to_keep_files + (5 * 86400)):
            #os.path.basename strips the absolute path of the file away
            #for example /tmp/test.file is turned into test.file
            #this is done so that tarballs can be created in specific directories
            #instead of in the directory where the original file was (which is default action)
            try:
                print "removing the following file:", archive_file, "--> it is older than ",((days_to_keep_files + (10 * 86400))/86400), "days"
                os.remove(archive_file)
            except Exception, error_archive:
                print error_archive
    print "The cleanup is complete and the disk usage is now: "
    print os.popen("df -h |grep -v usr |grep -v tmp |grep -v udev |grep -v var |grep -v home").read()
    print "-----------------------------------------------------------"

####################################backup procedures ########################################
    #This section is a sanity check to make sure there is enough space to complete the backups  
    free_space = os.popen("df -h |grep archive |awk '{print $3}'").read().strip()
    #We are going to assume that the free space will be displayed in Gb so we must strip off the "G" in order to evaluate
    #if there is not enough space after the cleaning, abort the program. Based on current backup sizes
    #The backups require approximately 200G to complete so we will use 210 as a buffer
    free_space = free_space.replace("G", "")
      
    if int(free_space) < 210:
        print "Error: there is not enough space on /archive to continue...ABORTING"
        #Change stdout back
        sys.stdout = old_stdout 
        sys.stderr = old_stderr
        #mail the error message
        mail_mes = 'mail -s "Not enough space for backup" %s < %s' % (email_addresses, logfile)
        os.system(mail_mes)
        sys.exit()
    else:
        print "/archive has at least 210G of free space. Commencing backup."

    #Suspend the virtual machines
    for individual_vm in read_vm_list():
        try:

            individual_vm = individual_vm.split(" {")
            print ""
            print "Suspending: %s" % (individual_vm[0]),
            print ""
            os.system('vboxmanage controlvm %s savestate' % (individual_vm[0]))
        except Exception, error_suspend:
            print "The following errors occured: "
            print error_suspend            

    #Change to the directory where the files should be dumped
    os.chdir(todays_directory)

    #This function returns the total number of tar processes running
    def getProcesses(search_process):
        number_of_processes = subprocess.Popen("ps ax | grep '%s' |grep -v grep |grep -v .vmx|grep -v .tar.gz |wc -l" % search_process, shell=True, stdout=subprocess.PIPE)
        output = number_of_processes.stdout.read()
        number_of_processes.stdout.close()
        number_of_processes.wait()
        return output

############vm_list parsing function ###########
    def split_individual_vm(vm):
            individual_vm = vm.split(" {")
            individual_vm = individual_vm[0]
            get_vm_info = os.popen("vboxmanage showvminfo %s" % individual_vm).read()
            
            if "vmdk" in get_vm_info:
                #Get the vmdk path from the info
                #We only care about the getting the folder name so we limit the output to a single entry
                #even if the VM has more than one hard drive
                get_vm_info = "vboxmanage showvminfo %s |grep vmdk |awk -F ':' '{print $2}' |head -n 1" % individual_vm
                #Get the base name as we want to tar up all the files in the folder
                vm_path = os.popen(get_vm_info).read().strip()
                vm_path = os.path.dirname(vm_path.replace(" (UUID" ,""))
            elif "vdi" in get_vm_info:
                  get_vm_info = "vboxmanage showvminfo %s |grep vdi |awk -F ':' '{print $2}' |head -n 1" % individual_vm
                  vm_path = os.popen(get_vm_info).read().strip()
                  vm_path = os.path.dirname(vm_path.replace(" (UUID" ,""))
                                   
            return vm_path

    for vms in read_vm_list():
        try:
            #This section gets the number of processes so that we know how many tar processes are running at a time
            output = getProcesses("tar_virtualbox_vms.py")
            vm_path = split_individual_vm(vms)
            print "tarring: ", vm_path
            ####end parsing ####
              
            os.system("python /backup_scripts/tar_virtualbox_vms.py %s %s &" % (vm_path, todays_directory))
            time.sleep(1)
            #Since vm-server has 8 cores, we are going to set the thread to 7
            #We will then ask the computer to wait 10 minutes before attempting another backup process 
            while int(output) > 5:
                output = getProcesses("tar_virtualbox_vms.py")      
                time.sleep(6)

        except Exception, error_tar:
            print "The following errors occured: "
            print error_tar  

    print "sleeping for 10 seconds"
    time.sleep(1)    
    #resume VMs
    for individual_vm in read_vm_list():
        try:
            vm_path = split_individual_vm(individual_vm)
            running_processes = getProcesses(vm_path)
            while int(running_processes) != 0:
                running_processes = getProcesses(individual_vm)
                print "sleeping because this vm: %s  is still being processed" % vm_path
                time.sleep(600)
            
            individual_vm = individual_vm.split(" {")
            individual_vm = individual_vm[0]
            print "Resuming: %s" % (individual_vm)
            print ""
            os.system("VBoxManage startvm %s --type headless" % (individual_vm))
        except Exception, error_resume:
            print "The following errors occured: "
            print error_resume

    print " "        
    print "VMs have been restarted successfully. Backup process is complete"
    print "-------------------------------------------------------------------------"
#####################backup complete#####################

####################check the tar files ###############
    for tar_file in find_files(todays_directory, '*.gz'):
        try:
            output = getProcesses("tar_virtualbox_vms.py")
            while int(output) !=0:
                print "there are files still being tarred"      
                time.sleep(6)
            print "checking ", tar_file
            sys.stdout.close()
                
            os.system("python /backup_scripts/check_tars.py %s &" % tar_file)
            time.sleep(5)
            running_tar_checks = getProcesses("check_tars.py")
            while int(running_tar_checks) > 5: 
                running_tar_checks = getProcesses("check_tars.py")    
                time.sleep(6)

        except Exception, error_tar_check:
            print error_tar_check

except Exception, e:
    e = str(e)
    print e
sys.stdout = open(logfile, "a")
sys.stderr = open(logfile, "a")
print "---------------------Backup processes is completed on this date: --------->", datetime.datetime.now().strftime("%Y-%m-%d-%H:%M"), "<----------"
print os.popen("df -h |grep -v usr |grep -v tmp |grep -v udev |grep -v var |grep -v home").read()
sys.stdout.close()
sys.stdout = old_stdout

######send mail ########
counter = 0

email_errors = []

if error_archive != "":
   email_errors.append("Error cleaning /archive")

if error_suspend != "":
    email_errors.append("Error suspending vms")

if error_tar != "":
    email_errors.append("Error while attempting to tar suspended vms")

if error_resume != "":
    email_errors.append("Error attempting to resume VMs")

if error_tar_check != "":
    email_errors.append("Error while testing tar archives")

os.system("echo 'The following error(s) was ecounter: '%s'.' > /backup_scripts/mail.txt" % (email_errors))

#In python a list which is not empty considered true, therefore if email_errors evaluates to true, run the error messages
if email_errors:
    mail_mes = "mutt -s 'Problems with vm backups' -a '%s' '%s' < /backup_scripts/mail.txt" % (logfile, email_addresses)
    os.system(mail_mes)
#If the list is blank email no problems
else:
    mail_mes = "echo 'The logs can be found at '%s'' |mail -s 'No problems with VM-weekly backup' %s " % (logfile, email_addresses)
    os.system(mail_mes)

os.system("rm -rf /backup_scripts/mail.txt")
 
created a script to change a user's default group in /etc/passwd

The thought behind this is, we want to remove the default stratus:stratus configuration on a server. However specifying the option with useradd -N still puts users in a group "users".

Since we have a long list of users we feed into a user add script and each of them need to have a different default group I have instead done bulk adds and then changed their default groups... We were modifying existing systems so for us, this was the most practical way of doing things

Code:
#!/usr/bin/python
#This program was designed to change the default group of specific people within /etc/passwd
import os
import sys
import fnmatch
import re
import fileinput

if len(sys.argv) < 4 or sys.argv[1] == "-h":
    print """
    This file is intended to change the default group of users in /etc/passwd
    It expects you have a list of users in some text file, the usernames seperated by a whitespace
    It will make a backup copy of the file you are working on to /tmp
    
    USAGE
    this_script.py <user_list file> <group number to insert> <passwd file location>
    """
    exit()

#read the list
peoples_group_to_change = sys.argv[1]
password = sys.argv[3]
people = open(peoples_group_to_change).readlines()
#make the backup
os.system("cp %s /tmp/" % password)

for individual_user in str(people).split(" "):
   individual_user = str(individual_user).strip("'[").strip("]").replace("\\n'", "").rstrip()
   for line in fileinput.FileInput(password, inplace = 1):
      if str(individual_user) in line:
        #Split the string into a list so that we can manipulate it
        line1 = line.split(":")
        #change the group number to the number specified by the user running this script
        line1[3] = sys.argv[2]
        #Change the list back into a string
        line1 = ":".join([str(y) for y in line1])
        print line.replace(line, line1),
      else:
        print line,
 
photo import tool

Here's a script I use as part of my photo work flow. It copies images from the current directory into ~/Pictures/yyyy/mm/dd according to the EXIF date tag or the time stamp on the file. There are other photo managers that will do this but I had difficulty with them crashing and/or introducing a lot of extra overhead. I just wanted something to copy files.

Bugs: If you use multiple cameras that create identical file names on the same date, only one file will be copied and subsequent matching files will be silently ignored.

My most recent addition was to add the capability to convert raw files for Nikon cameras. It could be easily modified to handle other raw formats. That introduced another bug in that the orientation for raw images is not handled correctly. They all come out landscape.

Code:
#!/bin/bash

# Goes through all jpeg files in current directory, grabs date from each
# and sorts them into subdirectories according to the date
# Creates subdirectories corresponding to the dates as necessary.


for fil in *.MOV *.JPG *.mov *.jpg *tif *NEF # Also try *.JPG
do
    if [ -e $fil ]; then # if it exists
        # try to get date from EXIF tags
        datepath="$(exiftags -i $fil 2>/dev/null | awk '/Image Created/{print $3 }' | sed s%:%/%g)"

        # otherwise get date from file time stamp
        if [ -z $datepath ]; then
            datepath="$(ls -g $fil | awk '{print $5 }' | sed s%-%/%g)"
        fi

# hack -- this test could be hoisted outside the loop
        if [ -z $PICTUREROOT ]; then
            datepath=$HOME/Pictures/$datepath
        else
            datepath=${PICTUREROOT}/$datepath
        fi

        # Create destination directory when needed
        if ! test -e "$datepath"; then
            mkdir -pv "$datepath"
        fi

#       mv -u $fil $datepath
        cp -np $fil $datepath
        if test ${fil:(-4)} = ".NEF" ; then
            fulloutputpath=$datepath/`basename $fil .NEF`.jpeg
            echo $fulloutputpath $fil
            dcraw -c -w $fil | cjpeg > $fulloutputpath
            exiftool -overwrite_original -tagsfromfile $fil $fulloutputpath
        fi

    fi
done

An undocumented feature is that if you set the environbment variable PICTUREROOT then the pictures will be copied to $PICTUREROOT/yyyy/mm/dd instead of the default location.
 
I am pretty sure I have made tweaks to my nginx upgrade script since I originally posted it so here is my latest update:

upgrade_nginx
Code:
#!/bin/bash

# set variables
version=$1
make_opts="-j5"
stop_services="nginx" #php-fastcgi
start_services="nginx" #php-fastcgi

function get_version {
        if [ -z ${version} ]
        then
                echo -ne "\nplease enter the nginx version number you would like to upgrade to (ex - '0.8.54'):  "
                read version
                version="nginx-${version}"
                echo ${version}
                echo -n "is this the version you would like to upgrade to? (y/n):  "
                read response
                if [[ "$response" == [nN] ]]; then
                        echo -e "\n\nplease try again"
                        unset version
                        get_version
                else
                        nginx_source
                fi
        else
                version="nginx-${version}"
                echo -ne "\nupgrading to ${version}";
                sleep 3
                nginx_source
        fi
}

function nginx_source {
        cd /opt

        if [ -e ${version}.tar.gz ]; then
                echo -e "\n${version}.tar.gz exists, skipping download..."
        else
                echo -e "\ndownloading source..."
                wget http://nginx.org/download/${version}.tar.gz
        fi

        if [ -d ${version} ]; then
                echo -e "\nremoving old source directory..."
                rm -rf ${version}
        fi

        if [ -e ${version}.tar.gz ]; then
                echo -e "\nextracting archive..."
                tar zxvf ${version}.tar.gz
                chown -R root:root ${version}
                cd ${version}
                nginx_upgrade
        else
                echo "${version}.tar.gz did not download correctly!"
                exit 1
        fi
}

function nginx_upgrade {
        echo -e "\nrunning 'configure' command..."
        ./configure \
          --sbin-path=/usr/local/sbin \
          --conf-path=/etc/nginx/nginx.conf \
          --error-log-path=/var/log/nginx/error.log \
          --pid-path=/var/run/nginx.pid \
          --lock-path=/var/lock/nginx.lock \
          --http-log-path=/var/log/nginx/access.log \
          --with-http_dav_module \
          --http-client-body-temp-path=/var/lib/nginx/body \
          --with-http_ssl_module \
          --with-http_realip_module \
          --http-proxy-temp-path=/var/lib/nginx/proxy \
          --with-http_stub_status_module \
          --http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
          --with-debug \
          --with-http_flv_module \
          --add-module=/opt/ngx_http_auth_pam_module-1.2 \
          --user=www-data \
          --group=www-data

        echo -e "\n\nplease check for configuration errors (press enter to continue)"
        read

        echo -e "\nrunning 'make' command..."
        make ${make_opts}

        echo -e "\n\nplease check for make errors (press enter to continue)"
        read

        echo -e "\n\nnew version number verification\n"
        echo "expected:  ${version}"
        echo -n "actual: ${newver}"
        ./objs/nginx -v
        sleep 1

        echo -en "\ndo the version numbers match? (y/n):  "
        read response
        if [[ "$response" == [nN] ]]; then
                echo -e "\n\ncheck for errors and try again."
                post_install_cleanup
        fi

        echo -e "\nstopping services..."
        for i in ${stop_services}
        do
        /etc/init.d/${i} stop
        done

        sleep 1

        echo -e "\ninstalling ${version}..."
        make install

        sleep 1

        echo -e "\nstarting services..."
        for i in ${start_services}
        do
        /etc/init.d/${i} start
        done

        post_install_cleanup
}

function post_install_cleanup {
        cd /etc/nginx

        if [ ! -d backups ]; then
                echo -e "\ncreating backup directory..."
                mkdir backups
        fi

        echo -e "\nremoving example files..."
        mv *.default backups/

        echo -e "\nremoving extracted source directory..."
        cd /opt
        rm -rf ${version}
        echo -e "\ndone.\n"
}

get_version


Now I happen to have a number of servers running nginx so in order to make it easier, I have another script that will run the upgrade script on each of them:

upgrade_nginx_all
Code:
#!/bin/bash

### set variables
version=$1
upgrade_cmd=/root/scripts/upgrade_nginx
list="athena.mbentley.net pandora.mbentley.net vps.mbentley.net pluto.mbentley.net"
#list="athena.mbentley.net vps.mbentley.net pluto.mbentley.net"


function get_version {
        if [ -z ${version} ]
        then
                echo -ne "\nplease enter the nginx version number you would like to upgrade to (ex - '0.8.54'):  "
                read version
        fi

        echo nginx-${version}
        echo -n "is this the version you would like to upgrade to? (y/n):  "
        read response
        if [[ "$response" == [nN] ]]; then
                echo -e "\n\nplease try again"
                unset version
                get_version
        else
                run_upgrades
        fi
}

function run_upgrades {
        for i in ${list}
        do
        echo -e "\n==== executing upgrade on ${i} ====";
        ssh root@${i} ${upgrade_cmd} ${version}
        echo -e "==== upgrade on ${i} complete ====\n";
        done
}

get_version
 
Last edited:
I have a couple of Virtualbox servers running on Debian hosts. While Virtualbox has their own Debian apt repositories, it takes a little bit of work to upgrade Virtualbox on a server that runs VMs 24/7. I've tried to script it out just so that you can download the .deb file but they have the build number in the file name and I haven't found anywhere can I can easily grab that so this is the best I have been able to do. I get emails daily about new updates so I know when I need to run the update script.

This will also download and install the latest extension pack automatically via command line.

vbox_upgrade
Code:
#!/bin/bash

/root/scripts/vm_service stop
/etc/init.d/vboxweb-service stop
/etc/init.d/vboxdrv stop

aptitude -y upgrade

## download and install latest extension pack
latest_ver=`curl -s http://download.virtualbox.org/virtualbox/LATEST.TXT`
cd ~
wget http://download.virtualbox.org/virtualbox/${latest_ver}/Oracle_VM_VirtualBox_Extension_Pack-${latest_ver}.vbox-extpack
VBoxManage extpack install --replace ~/Oracle_VM_VirtualBox_Extension_Pack-${latest_ver}.vbox-extpack
sleep 2
rm ~/Oracle_VM_VirtualBox_Extension_Pack-${latest_ver}.vbox-extpack

## restart services
/etc/init.d/vboxdrv restart
/etc/init.d/vboxweb-service restart

sleep 2

/root/scripts/vm_service start
 
I am pretty sure I have made tweaks to my nginx upgrade script since I originally posted it so here is my latest update:

Code:
if [ "$response" == "n" ] || [ "$response" == "N" ]; then

Sorry this bothered me, not sure why. Please replace with...

Code:
if [[ "$response" == [nN] ]]; then
 
Heh, thanks. I never claimed to be the best script writer ever. I go for pure functionality only :)

Most things I have just googled for and cobbled together so I greatly appreciate your feedback :thup:
 
Heh, thanks. I never claimed to be the best script writer ever. I go for pure functionality only :)

Most things I have just googled for and cobbled together so I greatly appreciate your feedback :thup:

I'm with you, I make it work, then try to make it short.
 
I'm "part of" the help desk here and they are having severe issues with their DNS server. It is registering everything as static and never updating unless forced. We are rolling out some new software to a 250 head count location and the scripts I wrote depended on proper name resolution or a constructed hosts file. Since it isn't fixed yet, I had to go with the latter. I couldn't find an option in nmap to ignore DNS servers, so I ended up using a Linux virtual machine and writing a BASH script for it. Worked very well.

You will need samba-client installed to use it, as it uses a NETBIOS request. The computers are in a domain, so you may need to change the nmblookup line. I couldn't think of an easier way, so I just strung piped commands together rather than using something like sed/awk. It will output a file that you can place directly in your Windows "host" file.
Code:
#!/bin/bash

for i in {0..255}
do
    #Change this IP to whatever range you want
    currentip="192.168.0.$i"
    currenthost=
    echo "Looking up $currentip"

    #Do the lookup, parse the output, and store it in the variable
    currenthost=`nmblookup -A $currentip | grep "<00>" | grep -v "<GROUP>" | cut -f 2 | cut --delimiter=" " -f 1`

    #If the variable is not blank, we got a response
    if [ $currenthost ]
      then
        echo "Found host $currenthost at address $currentip"
        echo -e "$currentip\t$currenthost" >> host
    fi

done
 
Having trouble with a collegue who is constantly getting around 'sudo' monitoring by using 'sudo -s' or 'sudo bash'. As you know this means that prevents entries in secure log. To get around this I added this to /etc/profile

Code:
HST=$(hostname)
USR=$(who -um | awk '{print $1}')
NAME=$(whoami)
if [[ ! -d $HOME/.sh_hist ]]
        then
        mkdir $HOME/.sh_hist
fi
HISTFILE=${HOME}/.sh_hist/${HST}_${USR}_as_${NAME}_$(date +%F).hist
echo `who -um` >> $HISTFILE
export HISTFILE

I found some hints of how to do this on the web and I modified it to suite my needs
 
I created a script to ease the creation of new VirtualBox vms from the CLI. If you dont have a GUI, or you are SSH'd in, this should save you some time.

As a bonus I have confirmed it is cross-platform. This works in Windows should you need it to (tested with Python 2.7.2 Windows 7 Pro)

Code:
#!/usr/bin/python
#This script will create a virtualmachine from the CLI

import os
import sys
import subprocess

#Determine which OS we are running on. I assume either linux or windows

OS = sys.platform
if "linux" in OS:
    vbox_binary = "vboxmanage"
else:
    vbox_binary = "C:\\Program Files\\Oracle\\Virtualbox\\VBoxmanage.exe"


print ""
print "This program is designed to take your input and create a virtualmachine without having access to the gui"
print ""

print """The most likely OS types are:
WindowsXP_64
Windows7
Windows7_64
Windows2003
Windows2008
Windows2008_64
RedHat
RedHat_64

"""

##############################Bare Minimum VM requirements##############################

#Get the information about the vm from the administrator
vm_name = raw_input("Please enter the name for this vm: ")
vdi_exists = raw_input("Does the virtual disk already exist? ")

#Try asking as few questions as possible. If the vdi already exists we can skip a lot of the questions
if "y" in vdi_exists.lower() or "yes" in vdi_exists.lower():
    vdi_location = raw_input("Ok, please enter the location of the vdi: ")
    iso_location = "none"
#If the vdi does not exist we need the user to tell us some more information
else:
    vdi_folder = raw_input("Please enter the path where the vdi for this vm will be stored: ")
    hdd_size = raw_input("Please enter the size of the hdd in Megs: ")
    vdi_location = vdi_folder + os.sep + vm_name + ".vdi"
    print ""
    subprocess.call([vbox_binary, 'createhd', '--filename', vdi_location, '--size', hdd_size])
    iso_location = raw_input("Please enter the FULL path to the iso to be used: ")   

os_type = raw_input("Please enter the OS Type: ")

ram = raw_input("How much ram should this machine have? ")
number_cpus = raw_input("How many cpus/cores do you want to commit to this vm? ")

#These are the basic requirements of any vm, we will just append to it as options are added
vbox_command = [vbox_binary, 'modifyvm', vm_name, '--memory', ram, '--boot1', 'dvd', '--boot2', 'disk', '--boot3', 'none', '--boot4', 'none', '--cpus', number_cpus]

#############################################################################################

############################Networking #####################################################

nic = raw_input("""How should the network be configured?
         bridged
         nat
         intnet (Internal)
         hostonly (Host-Only)
: """)

#Here I am adjusting the networking portion of the modifyvm command
#This just cleans the code up a bit
nic = nic.lower()
if "bridge" in nic:
    vbox_command = vbox_command + ['--nic1', 'bridged', '--bridgeadapter1', 'eth0']
elif "nat" in nic or "intnet" in nic or "hostonly" in nic:
    vbox_command = vbox_command + ['--nic1', nic]
#We dont want the network to be left blank or be incorrect therefore we default to natted interface
else:
    vbox_command = vbox_command + ['--nic1', 'nat']
        
print ""

#start creating the vm, first, create the dynamic disk
subprocess.call([vbox_binary, 'createvm', '--name', vm_name, '--ostype', os_type, '--register'])
#Do we want to turn on the vrde port?
remote_port = raw_input("Do you want to enable vrde? ")
if "y" in remote_port.lower() or "yes" in remote_port.lower():
    vrde_port = raw_input("Which port should vrde listen on? ")
    vbox_command = vbox_command + ['--vrde', 'on', '--vrdeport', vrde_port]

#############################################################################################


#Now that the options have been configured, load them into vbox
subprocess.call(vbox_command)

#Add the ide controller for dvd drives
subprocess.call([ vbox_binary, 'storagectl', vm_name,  '--name', '"IDE Controller"', '--add', 'ide'])

#Depending on wheter its Windows XP/2003 or newer such as 7 or 2008, we need to set the hard drive type
if "2003" in os_type or "XP" in os_type:
    subprocess.call([ vbox_binary, 'storageattach', vm_name, '--storagectl', '"IDE Controller"', '--port', '0', '--device', '0', '--type', 'hdd', '--medium', vdi_location])
    subprocess.call([ vbox_binary, 'storageattach', vm_name, '--storagectl', '"IDE Controller"', '--port', '0', '--device', '1', '--type', 'dvddrive', '--medium', iso_location])
else:
    subprocess.call([ vbox_binary, 'storagectl', vm_name, '--name', '"SATA Controller"', '--add', 'sata', '--controller', 'IntelAHCI'])
    subprocess.call([ vbox_binary, 'storageattach', vm_name, '--storagectl', '"SATA Controller"', '--port', '0', '--device', '0', '--type', 'hdd', '--medium', vdi_location])
    subprocess.call([ vbox_binary, 'storageattach', vm_name, '--storagectl', '"IDE Controller"', '--port', '0', '--device', '0', '--type', 'dvddrive', '--medium', iso_location])

start_vm = raw_input("Do you want to start the vm now? ")
if "y" in start_vm.lower() or "yes" in start_vm.lower():
    print "ok starting vm now"
    subprocess.call([vbox_binary, 'startvm', vm_name, '--type', 'headless'])
else:
    print "ok, exiting the setup program"
 
This is not a bin/program specifically but I thought I would throw it up in case someone was looking to create a live-cd /installer for CentOS.

I use this to deploy multiple versions of different servers. I have tweaked this quite heavily but for the actual live cd portion, I assembled it from around the web (as much as I would like to take credit for it all I cant :D )

Code:
lang en_US.UTF-8
keyboard us
timezone US/Eastern
auth --useshadow --enablemd5
selinux --enforcing
firewall --disabled

repo --name=base --baseurl=file:///var/www/html/centos/6/os/x86_64/Packages
repo --name=updates --baseurl=file:///var/www/html/centos/6/updates/x86_64/Packages
repo --name=SIT --baseurl=file:///var/www/html/centos/6/SIT
xconfig --startxonboot
part / --size 4096
services --enabled=sshd,haldaemon,mcstrans,NetworkManager,portmap,restorecond --disabled=anacron,auditd,bluetooth,cpuspeed,gpm,hidd,ip6tables,mdmonitor,microcode_ctl,netfs,network,nfslock,pcscd,readahead_early,readahead_later,rpcgssd,rpcidmapd,cups,abrt,lldpad,mcelog

%packages
syslinux
kernel
@base
@core
@basic-desktop
@internet-browser
@network-tools
@x11
@fonts
mtools
pax
python-dmidecode
genisoimage
nscd
xterm
xorg-x11-xdm
libXmu
gedit
nautilus-open-terminal
-abrt-addon-ccpp
-abrt-addon-kerneloops
-abrt-addon-python
-abrt-cli
-autofs
-b43-fwcutter
-cifs-utils
-dmraid
-firstboot
-fprintd-pam
-hunspell
-hunspell-en
-mdadm
-openswan
-samba-client
-spice-vdagent
-system-config-keyboard
-virt-what
-wacomexpresskeys
-wdaemon
-wireless-tools
-words

# livecd bits to set up the livecd and be able to install
memtest86+
#livecd-tools
anaconda
device-mapper-multipath
isomd5sum

%end

%post --log=/root/kickstart.log

##########
mkdir -p /root/Desktop

#Setup the SITDev install Icon
cat > /root/Desktop/Install\ SITDEV.desktop << EOF_SITDEVIcon
[Desktop Entry]
Name=Install SITDEV
Categories=System;Utility;X-Red-Hat-Base;X-Fedora;GNOME;GTK;
Exec=python /root/dynamic_kickstart_sitdev.py
Terminal=true
Type=Application
Icon=anaconda
Encoding=UTF-8
StartupNotify=true
NoDisplay=true
X-Desktop-File-Install-Version=0.15
EOF_SITDEVIcon

#Setup the SIT-ADMIN install Icon
cat > /root/Desktop/Install\ SIT-ADMIN.desktop << EOF_SIT-ADMINIcon
[Desktop Entry]
Name=Install SIT-ADMIN
Categories=System;Utility;X-Red-Hat-Base;X-Fedora;GNOME;GTK;
Exec=python /root/dynamic_kickstart_sitadmin.py
Terminal=true
Type=Application
Icon=anaconda
Encoding=UTF-8
StartupNotify=true
NoDisplay=true
X-Desktop-File-Install-Version=0.15
EOF_SIT-ADMINIcon

rm -rf /etc/yum.repos.d/*
cat > /etc/yum.repos.d/SIT.repo << EOF_repo
[local_base]
name=SIT CentOS
baseurl=http://192.168.88.9/centos/6/os/x86_64/Packages
#baseurl=file:///var/www/html/centos/6/os/x86_64/Packages
enabled=1
gpgcheck=0

[local_updates]
name=SIT CentOS Updates
baseurl=http://192.168.88.9/centos/6/updates/x86_64/Packages
#baseurl=file:///var/www/html/centos/6/updates/x86_64/Packages
enabled=1
gpgcheck=0

[SIT]
name=SIT CentOS Extra
baseurl=http://192.168.88.9/centos/6/SIT
#baseurl=file:///var/www/html/centos/6/SIT
enabled=1
gpgcheck=0

[dag_local]
name=Dag Extras
baseurl=http://192.168.88.9/centos/6/dag_mirror
enabled=0
gpgcheck=0



EOF_repo

## default LiveCD user
LIVECD_USER="situser"

#customize the livecd desktop
echo "rm -rf /root/Desktop/liveinst.desktop" >> /etc/profile
echo "gconftool-2 --set --type string /desktop/gnome/background/picture_filename /root/buildenv.png" >> /etc/profile
echo "gconftool-2 --type boolean --set /apps/nautilus/desktop/computer_icon_visible false" >> /etc/profile
echo "gconftool-2 --type boolean --set /apps/nautilus/desktop/trash_icon_visible false" >> /etc/profile
echo "gconftool-2 --type boolean --set /apps/nautilus/desktop/home_icon_visible false " >> /etc/profile

#get the files which will customize the installer.
#The install script will have to remove the original files and put these files in place
cd /usr/lib/anaconda/iw/
wget http://localhost/scripts/congrats_gui_sitdev.py
wget http://localhost/scripts/congrats_gui_sitadmin.py
cd /usr/lib/anaconda/
wget http://localhost/scripts/gui_sitdev.py
wget http://localhost/scripts/gui_sitadmin.py
cd /root
wget http://localhost/scripts/VBoxLinuxAdditions.run
wget http://localhost/scripts/dynamic_kickstart_sitadmin.py
wget http://localhost/scripts/dynamic_kickstart_sitdev.py
wget http://localhost/scripts/buildenv.png
wget http://localhost/scripts/progress_first.png
cp -f progress_first.png /usr/share/anaconda/pixmaps/
cp -f progress_first.png /usr/share/anaconda/pixmaps/progress_first-lowres.png
########################################################################
# Create a sub-script so the output can be captured
# Must change "$" to "\$" and "`" to "\`" to avoid shell quoting
########################################################################
cat > /root/post-install << EOF_post
#!/bin/bash

echo ###################################################################
echo ## Creating the livesys init script
echo ###################################################################

cat > /etc/rc.d/init.d/livesys << EOF_initscript
#!/bin/bash
#
# live: Init script for live image
#
# chkconfig: 345 00 99
# description: Init script for live image.

. /etc/init.d/functions

if ! strstr "\\\`cat /proc/cmdline\\\`" liveimg || [ "\\\$1" != "start" ]; then
    exit 0
fi

if [ -e /.liveimg-configured ] ; then
    configdone=1
fi


exists() {
    which \\\$1 >/dev/null 2>&1 || return
    \\\$*
}

touch /.liveimg-configured

# mount live image
if [ -b \\\`readlink -f /dev/live\\\` ]; then
   mkdir -p /mnt/live
   mount -o ro /dev/live /mnt/live 2>/dev/null || mount /dev/live /mnt/live
fi

livedir="LiveOS"
for arg in \\\`cat /proc/cmdline\\\` ; do
  if [ "\\\${arg##live_dir=}" != "\\\${arg}" ]; then
    livedir=\\\${arg##live_dir=}
    return
  fi
done

# enable swaps unless requested otherwise
swaps=\\\`blkid -t TYPE=swap -o device\\\`
if ! strstr "\\\`cat /proc/cmdline\\\`" noswap && [ -n "\\\$swaps" ] ; then
  for s in \\\$swaps ; do
    action "Enabling swap partition \\\$s" swapon \\\$s
  done
fi
if ! strstr "\\\`cat /proc/cmdline\\\`" noswap && [ -f /mnt/live/\\\${livedir}/swap.img ] ; then
  action "Enabling swap file" swapon /mnt/live/\\\${livedir}/swap.img
fi

mountPersistentHome() {
  # support label/uuid
  if [ "\\\${homedev##LABEL=}" != "\\\${homedev}" -o "\\\${homedev##UUID=}" != "\\\${homedev}" ]; then
    homedev=\\\`/sbin/blkid -o device -t "\\\$homedev"\\\`
  fi

  # if we're given a file rather than a blockdev, loopback it
  if [ "\\\${homedev##mtd}" != "\\\${homedev}" ]; then
    # mtd devs don't have a block device but get magic-mounted with -t jffs2
    mountopts="-t jffs2"
  elif [ ! -b "\\\$homedev" ]; then
    loopdev=\\\`losetup -f\\\`
    if [ "\\\${homedev##/mnt/live}" != "\\\${homedev}" ]; then
      action "Remounting live store r/w" mount -o remount,rw /mnt/live
    fi
    losetup \\\$loopdev \\\$homedev
    homedev=\\\$loopdev
  fi

  # if it's encrypted, we need to unlock it
  if [ "\\\$(/sbin/blkid -s TYPE -o value \\\$homedev 2>/dev/null)" = "crypto_LUKS" ]; then
    echo
    echo "Setting up encrypted /home device"
    plymouth ask-for-password --command="cryptsetup luksOpen \\\$homedev EncHome"
    homedev=/dev/mapper/EncHome
  fi

  # and finally do the mount
  mount \\\$mountopts \\\$homedev /home
  # if we have /home under what's passed for persistent home, then
  # we should make that the real /home.  useful for mtd device on olpc
  if [ -d /home/home ]; then mount --bind /home/home /home ; fi
  [ -x /sbin/restorecon ] && /sbin/restorecon /home
  if [ -d /home/\\\$LIVECD_USER ]; then USERADDARGS="-M" ; fi
}

findPersistentHome() {
  for arg in \\\`cat /proc/cmdline\\\` ; do
    if [ "\\\${arg##persistenthome=}" != "\\\${arg}" ]; then
      homedev=\\\${arg##persistenthome=}
      return
    fi
  done
}

if strstr "\\\`cat /proc/cmdline\\\`" persistenthome= ; then
  findPersistentHome
elif [ -e /mnt/live/\\\${livedir}/home.img ]; then
  homedev=/mnt/live/\\\${livedir}/home.img
fi

# if we have a persistent /home, then we want to go ahead and mount it
if ! strstr "\\\`cat /proc/cmdline\\\`" nopersistenthome && [ -n "\\\$homedev" ] ; then
  action "Mounting persistent /home" mountPersistentHome
fi

# make it so that we don't do writing to the overlay for things which
# are just tmpdirs/caches
mount -t tmpfs -o mode=0755 varcacheyum /var/cache/yum
mount -t tmpfs tmp /tmp
mount -t tmpfs vartmp /var/tmp
[ -x /sbin/restorecon ] && /sbin/restorecon /var/cache/yum /tmp /var/tmp >/dev/null 2>&1

if [ -n "\\\$configdone" ]; then
  exit 0
fi


## fix various bugs and issues
# unmute sound card
exists alsaunmute 0 2> /dev/null

# turn off firstboot for livecd boots
echo "RUN_FIRSTBOOT=NO" > /etc/sysconfig/firstboot

# turn off mdmonitor by default
chkconfig --level 345 mdmonitor       off 2>/dev/null

# turn off setroubleshoot on the live image to preserve resources
chkconfig --level 345 setroubleshoot  off 2>/dev/null

# don't start cron/at as they tend to spawn things which are
# disk intensive that are painful on a live image
chkconfig --level 345 auditd          off 2>/dev/null
chkconfig --level 345 crond           off 2>/dev/null
chkconfig --level 345 atd             off 2>/dev/null
chkconfig --level 345 readahead_early off 2>/dev/null
chkconfig --level 345 readahead_later off 2>/dev/null

# disable kdump service
chkconfig --level 345 kdump           off 2>/dev/null

# disable microcode_ctl service
chkconfig --level 345 microcode_ctl   off 2>/dev/null

# disable smart card services
chkconfig --level 345 openct          off 2>/dev/null
chkconfig --level 345 pcscd           off 2>/dev/null

# disable postfix service
chkconfig --level 345 postfix         off 2>/dev/null

# Stopgap fix for RH #217966; should be fixed in HAL instead
touch /media/.hal-mtab

# workaround clock syncing on shutdown that we don't want (#297421)
sed -i -e 's/hwclock/no-such-hwclock/g' /etc/rc.d/init.d/halt

# set the LiveCD hostname
sed -i -e 's/HOSTNAME=localhost.localdomain/HOSTNAME=SIT-BuildEnv/g' /etc/sysconfig/network
/bin/hostname SIT-BuildEnv

## create the LiveCD default user
# add default user with no password
/usr/sbin/useradd -c "LiveCD default user" $LIVECD_USER
/usr/bin/passwd -d $LIVECD_USER > /dev/null
# give default user sudo privileges
echo "$LIVECD_USER     ALL=(ALL)     NOPASSWD: ALL" >> /etc/sudoers

chmod 755 /home/$LIVECD_USER/Desktop/Install\ SIT-ADMIN.desktop

## configure default user's desktop
# set up timed auto-login at 10 seconds
cat >> /etc/gdm/custom.conf << FOE
[daemon]
TimedLoginEnable=true
TimedLogin=root
TimedLoginDelay=2
FOE

# add keyboard and display configuration utilities to the desktop
mkdir -p /home/$LIVECD_USER/Desktop >/dev/null
cp /usr/share/applications/gnome-display-properties.desktop /home/$LIVECD_USER/Desktop/

# disable screensaver locking
gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s -t bool   /apps/gnome-screensaver/lock_enabled "false" >/dev/null

# disable PackageKit update checking by default
gconftool-2 --direct --config-source=xml:readwrite:/etc/gconf/gconf.xml.defaults -s -t int /apps/gnome-packagekit/update-icon/frequency_get_updates "0" >/dev/null

# detecting disk partitions and logical volumes 
CreateDesktopIconHD()
{
cat > /home/$LIVECD_USER/Desktop/Local\ hard\ drives.desktop << EOF_HDicon
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Link
Name=Local hard drives
Name[en_US]=Local hard drives
Name[fr_CA]=Disques durs locaux
URL=/mnt/disc
Icon=/usr/share/icons/gnome/32x32/devices/gnome-dev-harddisk.png
EOF_HDicon

chmod 755 /home/$LIVECD_USER/Desktop/Local\ hard\ drives.desktop
}

CreateDesktopIconLVM()
{
mkdir -p /home/$LIVECD_USER/Desktop >/dev/null

cat > /home/$LIVECD_USER/Desktop/Local\ logical\ volumes.desktop << EOF_LVMicon
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Link
Name=Local logical volumes
Name[en_US]=Local logical volumes
Name[fr_CA]=Volumes logiques locaux
URL=/mnt/lvm
Icon=/usr/share/icons/gnome/32x32/devices/gnome-dev-harddisk.png
EOF_LVMicon

chmod 755 /home/$LIVECD_USER/Desktop/Local\ logical\ volumes.desktop
}

# don't mount disk partitions if 'nodiskmount' is given as a boot option
if ! strstr "\\\`cat /proc/cmdline\\\`" nodiskmount ; then
	MOUNTOPTION="ro"
	HARD_DISKS=\\\`egrep "[sh]d.\\\$" /proc/partitions | tr -s ' ' | sed 's/^  *//' | cut -d' ' -f4\\\`

	echo "Mounting hard disk partitions... "
	for DISK in \\\$HARD_DISKS; do
	    # Get the device and system info from fdisk (but only for fat and linux partitions).
	    FDISK_INFO=\\\`fdisk -l /dev/\\\$DISK | tr [A-Z] [a-z] | egrep "fat|linux" | egrep -v "swap|extended|lvm" | sed 's/*//' | tr -s ' ' | tr ' ' ':' | cut -d':' -f1,6-\\\`
	    for FDISK_ENTRY in \\\$FDISK_INFO; do
		PARTITION=\\\`echo \\\$FDISK_ENTRY | cut -d':' -f1\\\`
		MOUNTPOINT="/mnt/disc/\\\${PARTITION##/dev/}"
		mkdir -p \\\$MOUNTPOINT
		MOUNTED=FALSE

		# get the partition type
		case \\\`echo \\\$FDISK_ENTRY | cut -d':' -f2-\\\` in
		*fat*) 
		    FSTYPES="vfat"
		    EXTRAOPTIONS=",uid=500";;
		*)
		    FSTYPES="ext4 ext3 ext2"
		    EXTRAOPTIONS="";;
		esac

		# try to mount the partition
		for FSTYPE in \\\$FSTYPES; do
		    if mount -o "\\\${MOUNTOPTION}\\\${EXTRAOPTIONS}" -t \\\$FSTYPE \\\$PARTITION \\\$MOUNTPOINT &>/dev/null; then
			echo "\\\$PARTITION \\\$MOUNTPOINT \\\$FSTYPE noauto,\\\${MOUNTOPTION}\\\${EXTRAOPTIONS} 0 0" >> /etc/fstab
			echo -n "\\\$PARTITION "
			MOUNTED=TRUE
			CreateDesktopIconHD
		    fi
		done
		[ \\\$MOUNTED = "FALSE" ] && rmdir \\\$MOUNTPOINT
	    done
	done
	echo
fi

# don't mount logical volumes if 'nolvmmount' is given as a boot option
if ! strstr "\\\`cat /proc/cmdline\\\`" nolvmmount ; then
        MOUNTOPTION="ro"
	FSTYPES="ext4 ext3 ext2"
	echo "Scanning for logical volumes..."
	if ! lvm vgscan 2>&1 | grep "No volume groups"; then
	    echo "Activating logical volumes ..."
	    modprobe dm_mod >/dev/null
	    lvm vgchange -ay
	    LOGICAL_VOLUMES=\\\`lvm lvdisplay -c | sed "s/^  *//" | cut -d: -f1\\\`
	    if [ ! -z "\\\$LOGICAL_VOLUMES" ]; then
		echo "Making device nodes ..."
		lvm vgmknodes
		echo -n "Mounting logical volumes ... "
		for VOLUME_NAME in \\\$LOGICAL_VOLUMES; do
		    VG_NAME=\\\`echo \\\$VOLUME_NAME | cut -d/ -f3\\\`
		    LV_NAME=\\\`echo \\\$VOLUME_NAME | cut -d/ -f4\\\`
		    MOUNTPOINT="/mnt/lvm/\\\${VG_NAME}-\\\${LV_NAME}"
		    mkdir -p \\\$MOUNTPOINT

		    MOUNTED=FALSE
		    for FSTYPE in \\\$FSTYPES; do
			if mount -o \\\$MOUNTOPTION -t \\\$FSTYPE \\\$VOLUME_NAME \\\$MOUNTPOINT &>/dev/null; then
			    echo "\\\$VOLUME_NAME \\\$MOUNTPOINT \\\$FSTYPE defaults,\\\${MOUNTOPTION} 0 0" >> /etc/fstab
			    echo -n "\\\$VOLUME_NAME "
			    MOUNTED=TRUE
			    CreateDesktopIconLVM
			    break
			fi
		    done
		    [ \\\$MOUNTED = FALSE ] && rmdir \\\$MOUNTPOINT
		done
		echo

	    else
		echo "No logical volumes found"
	    fi
	fi
fi

# give back ownership to the default user
chown -R $LIVECD_USER:$LIVECD_USER /home/$LIVECD_USER
EOF_initscript


# bah, hal starts way too late
cat > /etc/rc.d/init.d/livesys-late << EOF_lateinitscript
#!/bin/bash
#
# live: Late init script for live image
#
# chkconfig: 345 99 01
# description: Late init script for live image.

. /etc/init.d/functions

if ! strstr "\\\`cat /proc/cmdline\\\`" liveimg || [ "\\\$1" != "start" ] || [ -e /.liveimg-late-configured ] ; then
    exit 0
fi

exists() {
    which \\\$1 >/dev/null 2>&1 || return
    \\\$*
}

touch /.liveimg-late-configured

# read some variables out of /proc/cmdline
for o in \\\`cat /proc/cmdline\\\` ; do
    case \\\$o in
    ks=*)
        ks="\\\${o#ks=}"
        ;;
    xdriver=*)
        xdriver="--set-driver=\\\${o#xdriver=}"
        ;;
    esac
done

# if liveinst or textinst is given, start anaconda
if strstr "\\\`cat /proc/cmdline\\\`" liveinst ; then
   plymouth --quit
   /usr/sbin/liveinst \\\$ks
fi
if strstr "\\\`cat /proc/cmdline\\\`" textinst ; then
   plymouth --quit
   /usr/sbin/liveinst --text \\\$ks
fi

# configure X, allowing user to override xdriver
if [ -n "\$xdriver" ]; then
    exists system-config-display --noui --reconfig --set-depth=24 \\\$xdriver
fi

EOF_lateinitscript

# workaround avahi segfault (#279301)
touch /etc/resolv.conf
/sbin/restorecon /etc/resolv.conf

chmod 755 /etc/rc.d/init.d/livesys
/sbin/restorecon /etc/rc.d/init.d/livesys
/sbin/chkconfig --add livesys

chmod 755 /etc/rc.d/init.d/livesys-late
/sbin/restorecon /etc/rc.d/init.d/livesys-late
/sbin/chkconfig --add livesys-late

# go ahead and pre-make the man -k cache (#455968)
/usr/sbin/makewhatis -w


# save a little bit of space at least...
rm -f /var/lib/rpm/__db*
rm -f /boot/initrd*
rm -f /boot/initramfs*
# make sure there aren't core files lying around
rm -f /core*

# convince readahead not to collect
rm -f /.readahead_collect
touch /var/lib/readahead/early.sorted

EOF_post

/bin/bash -x /root/post-install 2>&1 | tee /root/post-install.log

%end

%post --nochroot

########################################################################
# Create a sub-script so the output can be captured
# Must change "$" to "\$" and "`" to "\`" to avoid shell quoting
########################################################################
cat > /root/postnochroot-install << EOF_postnochroot
#!/bin/bash

# Copy licensing information
cp $INSTALL_ROOT/usr/share/doc/*-release-*/GPL $LIVE_ROOT/GPL

# add livecd-iso-to-disk utility on the LiveCD
# only works on x86, x86_64
if [ "\$(uname -i)" = "i386" -o "\$(uname -i)" = "x86_64" ]; then
  if [ ! -d \$LIVE_ROOT/LiveOS ]; then mkdir -p \$LIVE_ROOT/LiveOS ; fi
  cp /usr/bin/livecd-iso-to-disk \$LIVE_ROOT/LiveOS
fi

# customize boot menu entries
grep -B4 'menu default'  \$LIVE_ROOT/isolinux/isolinux.cfg > \$LIVE_ROOT/isolinux/default.txt
grep -B3 'xdriver=vesa'  \$LIVE_ROOT/isolinux/isolinux.cfg > \$LIVE_ROOT/isolinux/basicvideo.txt
grep -A3 'label check0'  \$LIVE_ROOT/isolinux/isolinux.cfg > \$LIVE_ROOT/isolinux/check.txt
grep -A2 'label memtest' \$LIVE_ROOT/isolinux/isolinux.cfg > \$LIVE_ROOT/isolinux/memtest.txt
grep -A2 'label local'   \$LIVE_ROOT/isolinux/isolinux.cfg > \$LIVE_ROOT/isolinux/localboot.txt


cat \$LIVE_ROOT/isolinux/default.txt \$LIVE_ROOT/isolinux/basicvideo.txt \$LIVE_ROOT/isolinux/check.txt \$LIVE_ROOT/isolinux/memtest.txt \$LIVE_ROOT/isolinux/localboot.txt > \$LIVE_ROOT/isolinux/current.txt
diff \$LIVE_ROOT/isolinux/isolinux.cfg \$LIVE_ROOT/isolinux/current.txt | sed '/^[0-9][0-9]*/d; s/^. //; /^---$/d' > \$LIVE_ROOT/isolinux/cleaned.txt
cat \$LIVE_ROOT/isolinux/cleaned.txt \$LIVE_ROOT/isolinux/default.txt \$LIVE_ROOT/isolinux/textboot.txt \$LIVE_ROOT/isolinux/basicvideo.txt \$LIVE_ROOT/isolinux/install.txt \$LIVE_ROOT/isolinux/textinstall.txt \$LIVE_ROOT/isolinux/memtest.txt \$LIVE_ROOT/isolinux/localboot.txt > \$LIVE_ROOT/isolinux/isolinux.cfg
rm -f \$LIVE_ROOT/isolinux/*.txt

# Forcing plymouth to show the logo in vesafb 
sed -i "s/rhgb/rhgb vga=791/g"	\$LIVE_ROOT/isolinux/isolinux.cfg

# Disabling auto lvm/disk mount (that will crash the "Install to Hard Drive feature")
sed -i "s/quiet/quiet nodiskmount nolvmmount/g"	\$LIVE_ROOT/isolinux/isolinux.cfg

# Fix the "liveinst doesn't start in gui mode when not enough memory available" - switching to terminal mode
sed -i "s/Terminal=false/Terminal=true/" \$LIVE_ROOT/home/centoslive/Desktop/liveinst.desktop

EOF_postnochroot

/bin/bash -x /root/postnochroot-install 2>&1 | tee /root/postnochroot-install.log

%end

%post --log=/root/post-post_install.log
yum remove samba* abrt cups pulseaduio -y
yum update -y
yum install kernel-devel kernel-headers gcc samba make -y
#export KERN_DIR=/usr/src/kernels/2.6.32-279.5.1.el6.x86_64/
sh /root/VBoxLinuxAdditions.run
%end
 
Back