Saturday, 3 May 2014

More about GNU tools on AIX

So I've got a script that creates and updates the httpd.conf configuration file used by IBM HTTP Server.

This script makes use of the sed command, and works perfectly on Linux, specifically Red Hat Enterprise Linux 6, both on x86-64 and z/Linux.

As an example, here's a portion of the script: -

...
sed -i'' 's/Listen 8080/#Listen 8080/g' httpd.conf
sed -i'' 's/#LoadModule ibm_ssl_module/LoadModule ibm_ssl_module/g' httpd.conf
sed -i'' 's/#Listen 443/Listen '${httpsPort}'/g' httpd.conf
sed -i'' 's/#<VirtualHost \*:443>/<VirtualHost \*:'${httpsPort}'>/g' httpd.conf
sed -i'' 's/#SSLEnable/SSLEnable/g' httpd.conf

...

Sadly, when I run this on AIX 7.1, it fails with: -

...
sed: Not a recognized flag: i
Usage:  sed [-n] [-u] Script [File ...]
        sed [-n] [-u] [-e Script] ... [-f Script_file] ... [File ...]
...

This is because, apparently: -

...
The -i option is a GNU (non-standard) extension to the sed command. It was not part of the classic interface to sed.
...


The solution ?

Of course, I needed to install the GNU version of sed from here: -

Once I did this, and updated the symbolic link for the sed binary to point at /opt/freeware/bin/sed, my script worked like a dream.

For the record, this is what I now have for sed : -

$ ls -al `which see`

lrwxrwxrwx    1 root     system           21 May 03 07:22 /usr/bin/sed -> /opt/freeware/bin/sed

No comments:

Note to self - use kubectl to query images in a pod or deployment

In both cases, we use JSON ... For a deployment, we can do this: - kubectl get deployment foobar --namespace snafu --output jsonpath="{...