I was working on a project at work to make installation of SLES 10 servers easier in the lab that I work in. One of the features of SuSE products is to save the configuration of a machine into an XML config file that will be later used by AutoYast to clone the machine. This is useful in a variety of cases such as mine where we have a lab that needs several machines installed and it takes time to go through the configuration on each install or in the case where a school or computing lab needs to install several nearly identical machines. This saves valuable time.
The AutoYast file can be stored on a network accessible machine and referenced later during installs. It can be named anything you like and then referenced later on the install line of Grub using the format:
autoyast=http://192.168.1.1/autoyast-conf-dir/autoyast-conf-file
However, you can also have several machines access the same directory and automatically get their unique configuration file. If a directory is specified, then the client tries to load a file with a name matching it’s IP address in HEX mode. Here’s a short snippet of bash to convert an IP address to HEX quickly in a way that could be used in a script:
#!/bin/sh
IP_ADDR=192.168.1.128
for I in $(echo ${IP_ADDR}| sed -e "s/\./ /g"); do
printf '%02X' $I
done
echo
Which has the output:
C0A80180
OR, as pointed out by Robin in the comments below this can be done much simpler using printf! The same result in a single command:
printf '%02X' ${IP_ADDR//./ }; echo
Yes, bash is awesome! :)
I have a configuration script that I run on each machine after it’s been installed. This sets up various NFS mount points, NTP, paths, etc. that we use for testing in the lab. All I need to do now is have this script automatically copy an AutoYast file to an NFS share if it exists or is different than an existing one. Once this is done, this file can later be referenced on installation of the client machine.
(Thanks to Robin for pointing out that my original script was not printing 2 places in the HEX number. Fixed.)
Happy scripting!
Comments
Leave a comment Trackback