I'm trying to write a script that can help me to change the hostname of the computer at the first boot. The reason why I need this script is because I manage a number of training computer and I use Ghost to re-image it every 2 months.
The script will read the mac address and the hostname from a csv file and compare it with the mac address on the current machine. I have stuck and don't know what is wrong as I'm new with script. Any help is highly appreciated.
# Change HOSTNAME for each machine from CSV file
# CSV File Format
# Each line contains two columns - mac address & hostname
# Description End
#Set variable for script
mac_addr=`ifconfig eth0 | grep HWaddr | cut -d ' ' -f 11`
if [ -z $1 ]; then
echo "Usage: `basename $0` <csv file>"
if [ -r $1 ]; then
cat $1 |
while read line; do
mac_org=$(echo $line | cut -d ' ' -f2)
hostname=$(echo $line | cut -d ' ' -f3\n)
if [ $mac_addr = $mac_org ]; then
sed "s/old_host/$hostname/g" $network_org > $network