0

Running a heterogeneous environment is always a challenge. Having an enterprise with AIX, IRIX, HPUX, Ultrix, Solaris, and several flavors of Linux, what is a good universal PATH setting that allows a good common set of commands, but also includes the extras, like 'ifconfig', 'ping', and 'make' that are often not there by default?

ericslaw
  • 1,562
  • 2
  • 13
  • 15

6 Answers6

3

$HOME/bin:$HOME/sbin:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/ccs/bin:/usr/ucb

In particular, you don't want to be adding to $PATH blindly in .bashrc or you end up with a mess on a sub-sub-sub-sub shell. You want to include all the sbin directories, because important tools can be there. You want to include /usr/ccs/bin:/usr/ucb as Solaris puts a few things you're likely to use in there.

Notably missing are the infinite permutations of choices for local installations of software, e.g. the GNU tools - usually you want them in the PATH before the system versions. Also, I left out directories that are more likely to be useful as a historical curiousity, like /etc and /usr/libexec.

It's endlessly debatable whether the Solaris /usr/ccs/bin should be before or after the GNU versions of the utilities. Realistically, you'll have occasional problems because of this no matter which way you choose.

carlito
  • 2,489
  • 18
  • 12
2

I use a combination of checks and tests to set my path on any given system via my .bashrc/.profile:

First - set a basic path which should be valid anywhere. Then you need to know where you're running:

# Bootstrap
unset PATH
PATH="/usr/bin:/bin:/sbin:/usr/sbin"

# What is the OS and Revision?
if [ -x /bin/uname ] || [ -x /sbin/uname ] || [ -x /usr/bin/uname ]; then
    OS=`uname -s`
else
    OS="unknown"
fi

Then you can add OS specific paths:

case $OS in
    Linux)
        ...
    ;;
    SunOS|Solaris)
        ck_add2path /usr/ucb /usr/ccs/bin
    ;;
esac

Where ck_add2path is defined as:

function add2path () {
    for NEWPATH in ${1+"$@"}; do
        if [ -z "$PATH" ] ; then
            export PATH="$NEWPATH"
        elif [ -z `echo ":$PATH:"|grep $NEWPATH` ] ; then
            export PATH="$PATH:$NEWPATH"
        fi
    done
    unset NEWPATH
}

function ck_add2path () {
    for NEWPATH in ${1+"$@"}; do
        NEWPATH=`echo $NEWPATH | sed 's/\/\//\//g'`
        if [ -d $NEWPATH ]; then
            add2path $NEWPATH
        fi
    done
    unset NEWPATH
}
dsully
  • 21
  • 1
1

For the root user, I'd be very careful; and by that I mean to not try and use a common PATH, do it per OS if you have to.

UNAME=`uname -s`
if [ "x${UNAME}" = "xLinux" ]; then
elif ....

A little extra work, but you don't want any surprises.

For non-root, there's so many...

  • /{bin,sbin}
  • /usr/{bin,sbin}
  • /opt/{bin,sbin}
  • /usr/local/{bin,sbin}
  • /sw/bin

The problem I've had in the past, specially with AIX, is that for some commands, you want your 3rd party install to take precedence, so then you place /opt/bin before /bin for example. Later things break because other utilities rely on the PATH to give them the native tool in /bin/.

Xerxes
  • 4,133
  • 3
  • 26
  • 33
  • I'm assuming that you have users' home directories in NFS mounted home directories. Each shell has different sequence of file usages. I find it best to configure each type of system (AIX, HPUX, Solaris, Linux) specifically in the /etc/profile, etc. Then only add what is really per user specific into their .bashrc, .profile, etc. Another trick that works really well is to only use /usr/local/bin and populate that with symbolic links to the "appropriate" executables. But that depends upon your user population and their needs. – CyberFonic May 29 '09 at 23:47
  • In the NFS environments where I was not an admin, the local profile was inconsistent and bare, thus forcing me to give up utilizing the default starting PATH. Using a global start path grew from having a single account across multiple machines (and writing scripts for same). Good point about the surprises however. – ericslaw Jun 01 '09 at 17:27
0

They're 'there' but often in /sbin and/or /usr/sbin. My .bashrc includes:

# I'm a sysadmin, RAAR!
PATH="${PATH}":/usr/sbin:/sbin

# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
    PATH=~/bin:"${PATH}"
fi  
pjz
  • 10,497
  • 1
  • 31
  • 40
0

I'd started with saving my old path before modifying it, so that subsequent calls to my startup scripts would not result in ever increasing PATH values... But after a while I ended up just setting it to a nice empirically established baseline.

I wanted X11 (even if only to call eval resize on remote ssh sessions to establish COLUMNS and LINES environment variables)

I added /usr/css/bin because some of my bare solaris installs didn't have make in the path (and even fewer even had cc or gcc!)

Of course the /usr/local/ set of paths were added, and then stuff in my homedir (both with and without architecture specific paths) and '.'.

The line with '.' in the path is questionable if you are root however.

OLDPATH=/bin:/usr/bin:/usr/5bin:/usr/bsd:/usr/ucb:/sbin:/usr/sbin
PATH=${OLDPATH}
PATH=${PATH}:/usr/openwin/bin:/usr/bin/X11:/usr/local/X11/bin
PATH=${PATH}:/usr/ccs/bin
PATH=/usr/local/bin:${PATH}
PATH=${PATH}:/etc:/usr/etc:/usr/local/etc
PATH=.:${HOME}/bin/`uname`:${HOME}/bin:${PATH}
export PATH

This setup has served me well across AIX, HPUX, IRIX, Ultrix, Solaris and Linux so far. Maybe even on those ancient apollo's (anyone see /usr/5bin anymore?)

ericslaw
  • 1,562
  • 2
  • 13
  • 15
0

I second dsully's programmatic approach for testing directories and adding paths. Also, when I add $dir to $PATH, I normally add $dir/../man to $MANPATH (if it exists).

Norman Ramsey
  • 645
  • 2
  • 10
  • 24