Sunday, October 19, 2008

Changing the Solaris root shell to bash

Bourne shell may be okay, but I'm a big bash fan myself. So I prefer using doing an "exec bash" after logging in as root. This can be a bit of a pain after a while though, so it would be great to have it automatically use bash. The problem is that some Solaris patching mechanisms may expect Bourne shell to be the default root shell, so if you simple go and change the root shell to bash you could get some unexpected results.

To work around this, edit the /etc/profile (which is the root user's shell profile), and add the snippet of code at the bottom, after all the initialization stuff is finished.

INITIALUSER=`who am i | awk '{print $1}'`
if [ "x$INITIALUSER" = "xjsmith" ]; then
if [ "x$BASH" = "x" ] ; then
exec bash
fi
fi

The code just checks who you are, and if you're a particular user, and your shell isn't already bash, then do an "exec bash". If you have a few users that are root you can simply expand the first if statement using some "or" logic.

No comments: