Are these devices on the same network, or configured and shipped.
One tool that manages configurations on a large network is cfengine. It is designed to work on large heterogeneous networks.
---
You mentioned that you are creating clones of an image, onto devices, and then editing files that are on the device.
It's possible to mount a clone of the image before writing them to a device (loop device) and edit the files locally.
---
Sed and awk are often used to edit configuration files. Awk is good for highly structured text tables. I think the first part, reading the configuration filename and the modification to make from a table, may be better done by awk then sed.
In sed, you can use the form sed '/pattern in line to edit/s/oldpattern/newpattern/' file. The first pattern will select which line to edit.
This could be done in a script where the pattern, s command LFS, and RFS values are variables.
sed "/$PAT/s/$OLDPAT/$NEWPAT/q" "$file". The variable values could be extracted from a database text file.
One trick I often use is to have a sed script extract the information I use in the form of bash assignment, and then use eval to create these variables. For example, I have a script to convert OGG files to MP3s. A function extracts information about ogg files returning tag values in VARIABLE=value form. The output of the function is eval'ed, setting the variables, which are used as arguments to a command setting the tags.
Another possibility is to use HERE documents to create the configuration files on the target.
HERE documents take their input from text in the script.
Code:
~> cat genfiles.sh
IPADDR1='192.168.2.100'
IPADDR2='192.168.2.110'
HOSTNAME1=dopey.site
HOSTNAME2=sleepy.site
ALIAS1=${HOSTNAME1%%.*}
ALIAS2=${HOSTNAME2%%.*}
cat >hosts <<- EOF
#
# hosts This file describes a number of hostname-to-address
# mappings for the TCP/IP subsystem. It is mostly
# used at boot time, when no name servers are running.
# On small systems, this file can be used instead of a
# "named" name server.
# Syntax:
#
# IP-Address Full-Qualified-Hostname Short-Hostname
#
127.0.0.1 localhost
# special IPv6 addresses
::1 localhost ipv6-localhost ipv6-loopback
fe00::0 ipv6-localnet
ff00::0 ipv6-mcastprefix
ff02::1 ipv6-allnodes
ff02::2 ipv6-allrouters
ff02::3 ipv6-allhosts
127.0.0.2 $HOSTNAME1 $ALIAS1
$IPADDR1 $HOSTNAME1 $ALIAS1
$IPADDR2 $HOSTNAME2 $ALIAS2
EOF
cat >HOSTNAME <<- EOF
$HOSTNAME1
EOF
Code:
~> cat hosts
#
# hosts This file describes a number of hostname-to-address
# mappings for the TCP/IP subsystem. It is mostly
# used at boot time, when no name servers are running.
# On small systems, this file can be used instead of a
# "named" name server.
# Syntax:
#
# IP-Address Full-Qualified-Hostname Short-Hostname
#
127.0.0.1 localhost
# special IPv6 addresses
::1 localhost ipv6-localhost ipv6-loopback
fe00::0 ipv6-localnet
ff00::0 ipv6-mcastprefix
ff02::1 ipv6-allnodes
ff02::2 ipv6-allrouters
ff02::3 ipv6-allhosts
127.0.0.2 dopey.site dopey
192.168.2.100 dopey.site dopey
192.168.2.110 sleepy.site sleepy
Code:
cat HOSTNAME
dopey.site
Here I parametrized the values which would change from one device to another. The variable values could have been read in by `read' or `awk' or `sed', or sourced from a file with a bunch of NAME=VALUE entries. This script has 2 HERE documents, creating hosts and hostname. I removed the "/etc/" from target filenames to prevent modifying the real files for a real test.
A spreadsheet could be exported to a csv file. Or you could use libreoffice and use xsltproc in a script, to translate the tables to a text table that your script can read in.
You could use variables of the form FILENAME_VARIABLE to prevent collisions.
---
Sed also has other commands that can insert lines or add lines. You could match a comment line in a template file and add a line after it with sed's 'a' command.
You can also have template files with dummy values that sed can find easily, and replace with real values.
_UNIT10_IPADDRESS_ _UNIT10_HOSTNAME_ _UNIT10_ALIAS_