Updating Your Login Scripts For RedHat Enterprise Linux

Contents

  1. Why Are Things Changing?
  2. Login Files
  3. Testing For System Types
  4. Sourcing Safely
  5. Custom Scripts
  6. Handling Paths
  7. Loading Modules
  8. Example Login Scripts
  9. Getting Help

Why Are Things Changing?

As part of the transition to new systems running RedHat Enterprise Linux, the structure of the file systems containing applications has changed from a monolithic layout of applications to a more modular approach using modules (pun intended). The most obvious change is that anything referring to a path in /usr/local must be changed to a new path in /usr/pppl. Another result of /usr/pppl is that modules provides a consistent means for users to setup their own environment. On the older UNIX systems at PPPL, there was no standard means for setting one's environment, instead setup was done through one's logins scripts. The setup done is a user's login scripts often times has a negative affect on the newer enterprise Linux systems.

This guide will explain to you the common issues users will see in there login scripts, along with recommendations and work arounds.

Login Files

The several files found in the root of your home directory ( ~/ ) are processed each time your login to a system. If you use bash or sh as your shell, .profile, .bash_profile (bash only), and .bashrc (bash only) are processed. If you use tcsh or csh, .login, .cshrc, and .tcshrc (tcsh only) are processed. You should examine each of these files and follow the recommendations given below to ensure things work smoothly on the enterprise Linux systems.

Testing For System Types

Since your login scripts will run on both the new and old systems, you will probably want to still have your old login code run on the older systems, but have different code run on the newer systems. Here is are recommended tests that you can do to determine to system type:

If you're using bash or sh, try:

	#!/bin/sh
	/bin/grep Enterprise /etc/redhat-release >/dev/null 2>&1
	if [ "$?" == "0" ]
	then
	   #
	   # This system is a new enterprise linux system
	   #
	   echo "I'm on a new system"
	else
	   #
	   # This is an older system
	   #
	   echo "I'm on an old system"
	fi
				

If you're using tcsh or csh, try:

	#!/bin/csh
	/bin/grep Enterprise /etc/redhat-release >& /dev/null
	if ( "$?" == "0" ) then
	   #
	   # This system is a new enterprise linux system
	   #
	   echo "I'm on a new system"
	else
	   #
	   # This is an older system
	   #
	   echo "I'm on an old system"
	endif
				

Sourcing Safely

On the older systems, several non-standard setup files existed, such as /etc/login.default. Being non-standard, these files do not exist on the new systems. As a result, any attempt to source these files will generate an error. Furthermore, in some csh and tcsh shells, failure to source a file will cause the login scripts to stop processing. The recommended fix is to first test if a file exists before sourcing it. For example, the following line is in many user's .login files:

	source /etc/login.default
				
This should be change to include a test to see if a file exists and can be read, such as:
	/usr/bin/test -r /etc/login.default && source /etc/login.default
				
Note that the syntax for this test will work on all shells and systems.

Custom Scripts

On the older PPPL UNIX systems, some custom commands existed and are still referenced in many login files. In general, you can replace something like:

	/usr/bin/my_custom_script
				
with a test like:
	/usr/bin/test -x /usr/bin/my_custom_script && /usr/bin/my_custom_script
				

The two most commonly referenced special scripts are hostnm (/usr/bin/hostnm) and os (/usr/bin/os). hostnm simply returns the short hostname, and can be replaced with:

	HOSTNAME=`/bin/uname -n | awk -F. '{print $1}'`
				
os is another custom script used to check what operating system as host is running. In general, uname can do the same thing. For example:
	if [ "`/bin/uname`" == "Linux" ]
	then
	  echo "I'm on a Linux machine"
	fi
	if [ "`/bin/uname`" == "SunOS" ]
	then
	  echo "I'm on a Solaris machine"
	fi
				

Handling Paths

Many users add custom paths as part of there environment setup. When doing this, it's important to append to paths, rather then setting the path. Doing something like:

	setenv PATH /my/path/to/stuff:/some/other/path
				
overwrites the existing paths. Overwriting a path will mostly likely cause you to lose some functionality, and can cause all sorts of program errors. It's much safer to change the above example into:
	setenv PATH /my/path/to/stuff:/some/other/path:${PATH}
				
This will preserve any existing path, and will ensure that you do not lose access to some programs, libraries, and files. Here some common path variables that you should always append to, rather then setting directly:
	PATH   MANPATH   LD_LIBRARY_PATH   LD_RUN_PATH   INCLUDE_PATH   C_INCLUDE_PATH
				

Loading Modules

You may have a favorite set of modules that you wish to use, or, for batch users, a set that's required for your code to run correctly. To have modules load automatically when you login, simply add

	module load my_compiler
	module load my_library
	module load ...
				
to your startup files.

Example Login Scripts

Here is an example .profile script for bash and sh shells:

	#!/bin/sh
	#
	# Sample .profile
	#
	/bin/grep Enterprise /etc/redhat-release >/dev/null 2>&1
	if [ "$?" == "0" ]
	then
		#
		# This is a new system, so we have modules
		#
		module load nstx
		module load lff95
		module load mpich
	else
		#
		# This is an old system, use 'setup'
		#
		setup nstx
	fi
	
	#
	# My alias
	#
	alias rm='rm -i'
	alias cp='cp -i'
	alias mv='mv -i'
	
	#
	# My Environment Variables
	#
	/usr/bin/which nano >/dev/null 2>&1 && export EDITOR=nano
	/usr/bin/which pico >/dev/null 2>&1 && export EDITOR=pico
	export PAGER=less
	export WORKDIR=/local/${USER}
	
	#
	# My Custom Paths
	#
	export PATH=~colleague/bin:${HOME}/bin:${PATH}
	export LD_LIBRARY_PATH=${HOME}/lib:${LD_LIBRARY_PATH}
			

Here is an example .login script for tcsh and csh shells:

	#!/bin/csh
	#
	# Sample .login
	#
	/bin/grep Enterprise /etc/redhat-release >& /dev/null
	if ( "$?" == "0" ) then
		#
		# This is a new system, so we have modules
		#
		module load nstx
		module load lff95
		module load mpich
	else
		#
		# This is an old system, use 'setup'
		#
		setup nstx
	fi
	
	#
	# My alias
	#
	alias rm='rm -i'
	alias cp='cp -i'
	alias mv='mv -i'
	
	#
	# My Environment Variables
	#
	/usr/bin/which nano >& /dev/null && setenv EDITOR nano
	/usr/bin/which pico >& /dev/null && setenv EDITOR pico
	setenv PAGER less
	setenv WORKDIR /local/${USER}
	
	#
	# My Custom Paths
	#
	setenv PATH ~colleague/bin:${HOME}/bin:${PATH}
	if ($?LD_LIBRARY_PATH) then
		setenv LD_LIBRARY_PATH ${HOME}/lib:${LD_LIBRARY_PATH}
	else
	  	setenv LD_LIBRARY_PATH ${HOME}/lib
	endif
		

Getting Help

Login scripts can be very complex and difficult. If you encounter problems adjusting your scripts for the new Linux systems, please contact us for help.