Just had a quick question for you all...not sure if this post belongs in this forum and if it does not I apologize. It involves BASH shell scripting.
At my company I am building a new template that is used to build Ubuntu VDIs. It is based on Xen.
The way that this works is...the creator of the VDI is allowed to pick a "template" that they then assign a name, ID, and overhead number to. There are many templates and each has different stuff installed...such as a 32-bit 10.04 template, a 64-bit 12.04 template, a 12.04 template with Hadoop...you get the idea.
Anyhow, when these machines are being built a shell script goes out to an FTP server where the name of the VDI (picked by the builder) is stored as a textfile. Each textfile is identified by a MAC address and each new machine is given a MAC one step up from the last. So...if I built a machine for myself my VDI name--let's say its "rdamato"--is stored as a one-line textfile. The file is named by whatever the VDIs MAC is going to be...so let's say mine is 00:00:00:00:00:23. One of the buildscripts gets the machine name by going to the FTP server that the textfile "00:00:00:00:00:23.txt" is stored on, then the variable $HOSTNAME is set to the contents of this file, which would be the single line "rdamato." Hey, I didn't come up with it! ; ')
Anyhow, my skills with sed are VERY rusty. What I am trying to do seems simple enough. One of the buildscripts uses the above information to generate an /etc/hosts file. So...I have a file that contains something like:
...and so on.Code:127.0.0.1 localhost 127.0.1.1 rdamato.companydomain.com company domain #IPv6 stuff fe00::0 ip6-localnet ff00:0 ip6-mcastprefix
What I am trying to do is to insert the line "126.96.36.199 companydnsserver.domain.com" AFTER all of the 127.x.x.x lines, but BEFORE anything else.
Obviously I would use sed to do this, but the exact syntax is throwing me off big time.
So basically, sed would be running in a script, and it would be inserting the SAME line each and every time. Seems easy enough, right? Well...maybe for youit is!! I am having a bear of a time doing it.
Anyhow, if anybody has any tips or suggestions as to how to go about this chore, it would be greatly appreciated. Thank you!