Good day members,

I am a noob at scripting and was looking into setting up a script that would automate my task of managing DHCP. I am looking at having a script that will search for a mac address, hostname and ipaddress; it will return it's findings then ask you what to do. You will have several options like, Add entry, disable entry, enable entry and maybe more in the future. I have a really basic outline going but am stuck with getting the enable disable part going.

As it is right now the search returns the line if it finds anything and it reports what line number the result is on.
I am looking at adding a section to add a semicolon to the beginning of that line to disable the entry and remove the semicolon to activate that entry.

Here is what I have so far, any help will be appreciated.

#!/bin/bash
# DHCP maintenance program to manage dhcp entries.
##
# Created by: Francisco Ramirez On: 01-01-2010
# Last updated by: On:

clear
echo " Welcome to the DHCP maintenance wizard";
echo "----------------------------------------"; echo "";

# File to work on
filename="/etc/dhcp3/dhcpd.master"

# Make a backup just in case
echo "Making a backup should an emergency arise.";
sudo cp $filename $filename.old
echo "Backup complete.";

# Ask user for input
echo -e "Please provide hostname, macaddress and ipaddress: "
read hostname macaddress ipaddress

# Search for Hostname
egrep -n "$hostname"\|"$macaddress"\|"$ipaddress" "$filename"
if [ $? = 0 ]
then
echo "Entry(ies) found."
else
echo "Nothing found."
fi

# Ask user what to do next
echo "Enter the number for what you want me to do:"
echo "1) Add a new entry."
echo "2) Activate entry."
echo "3) Disable the entry."
echo "4) Update mac address."
echo "5) Quit."
read case;

# Add a new entry
if [ "$case" = 1 ]
then
echo " host $hostname { hardware ethernet $macaddress; fixed-address $ipaddress; }" >> $filename
if [ $? = 0 ]
then
echo "Success!"
else
echo "Failed to make entry."
fi
fi

# Activate current entry

# Disable current entry

# Update MAC Address

# Exit to shell
if [ "$case" = 5 ]
echo "Good Bye."
then
exit 0
fi