Tag Archives: commands

Sed off

I’m sure many are familiar with the general substitute method of sed for replacing something in a file, i.e. sed -i s/this/that/g ~/myfile but recently I wanted to replace an entire line in a file, using bash.

I wanted to modify the localhost entry in /etc/hosts to include the static hostname too, all tab delimited. This is how I did it.
sed -i /^\\\t`hostname -f`\\t`hostname`\\tlocalhost.localdomain\\tlocalhost /etc/hosts

Find the line that begins with and replace it with itself, plus the result of the hostname commands, etc. This gives me a line like so:   pc.fqdn   pc   localhost.localdomain   localhost

I’m sure someone else knows a much more efficient way of doing this, but oh well, it works 🙂


Changing priorities

I’m scripting some sys admin tasks in Debian which require the installation of packages like Postfix. I don’t want it to prompt me with questions, so I knew I had to set the priority to something higher for this specific package (i.e. temporarily). There doesn’t appear to be a way to pass this to an apt-get command (which was a little disappointing) but debconf can set it system wide under /var/cache/debconf/config.dat, but that’s, well, ugly.

Turns out there’s an environment variable you can set to achieve what I want, DEBIAN_PRIORITY. So exporting this variable and unsetting it post install will do the trick, but I still think apt-get -p critical install postfix would be better 🙂