Difference between revisions of "Important .bashrc guidelines"

From oldwiki.scinet.utoronto.ca
Jump to navigation Jump to search
Line 53: Line 53:
 
     *)          MACHINE='unknown';;
 
     *)          MACHINE='unknown';;
 
esac
 
esac
HOST=$(uname)
 
  
 
if [ "${MACHINE}" == "tcs" ]  
 
if [ "${MACHINE}" == "tcs" ]  
Line 102: Line 101:
 
export BASH_ENV=~/.bashrc
 
export BASH_ENV=~/.bashrc
  
HOST=$(uname)
+
# what machine/architecture
 +
HOSTNAME=$(hostname)
 +
case $(uname -p) in
 +
    'ppc64')   MACHINE='p7';;
 +
    'powerpc')  MACHINE='tcs';;
 +
    'x86_64')  MACHINE='gpc';;
 +
    *)          MACHINE='unknown';;
 +
esac
  
if [ "${HOST}" == "AIX" ]; then
+
if [ "${MACHINE}" == "tcs" ]
 +
then
 
         # do things for the TCS machine
 
         # do things for the TCS machine
 
         # user environment for all shells goes here
 
         # user environment for all shells goes here
 
         # replace colon with your own commands
 
         # replace colon with your own commands
 
         :
 
         :
else
+
elif [ "${MACHINE}" == "p7" ]
 +
then
 +
        # do things for the P7 machine
 +
 
 +
        module load pe vacpp xlf
 +
 
 +
        # user environment for all shells goes here
 +
        # replace colon with your own commands
 +
        :
 +
elif [ "${MACHINE}" == "gpc" ]
 +
then
 
         # do things for the GPC machine
 
         # do things for the GPC machine
  
Line 117: Line 134:
 
         # replace colon with your own commands
 
         # replace colon with your own commands
 
         :
 
         :
 +
else
 +
        echo "Not a recognized system"
 
fi
 
fi
 
</source>
 
</source>

Revision as of 10:41, 4 August 2011

The file .bashrc, located in your home directory, is read-in and executed whenever a bash script or bash shell is started. The exception is for login shells, in which case .bash_profile is started. The default .bash_profile calls .bashrc so that many scinet users never need to edit .bash_profile.

This means in particular that the file .bashrc is read in

  • when you log in
  • when you run compute jobs
  • when you run certain commands such as mpirun
  • at the end of a job, when copying output and error files.

And that both on the GPS and the TCS, which nonetheless often require quite a different setup.

Guidelines

To avoid difficulties, you are advised to follow these guidelines in .bashrc:

  • Sourcing /etc/profile and /etc/bashrc is required for various SciNet routines to work!
  • Do not execute any commands that write to standard output, because that would breaks things like copying-out output files and scp. So for instance, no echo or module list.
  • Load only commonly used modules.
  • Distinguish, especially for the module command, between the gpc and tcs.
  • If you're trying out different implementations or versions of a module (e.g. mpi), you should not load them in the .bashrc, but explicitly on the command line before compiling and once more explicitly in your job script.
  • To avoid accidentally compiling on the login nodes, you can 'shield' yourself from the compilers by wrapping the module load commands with hostname check in the .bashrc file, e.g. as follows:

<source lang="bash"> HOSTNAME=$(hostname) if [ "${HOSTNAME:0:6}" != "scinet" ]; then

   module load intel openmpi  # and any other modules

fi </source>

Default .bashrc/.bash_profile

The default startup scripts provided by SciNet are as follows. Certain things - like sourcing /etc/profile and /etc/bashrc are required for various SciNet routines to work!

.bash_profile <source lang="bash"> if [ -f /etc/profile ]; then

      . /etc/profile

fi

  1. commands which work for both GPC and TCS can go here

alias passwd='echo "Please use the SciNet portal to change password: https://portal.scinet.utoronto.ca/change_password"'

  1. what machine/architecture

HOSTNAME=$(hostname) case $(uname -p) in

   'ppc64')    MACHINE='p7';;
   'powerpc')  MACHINE='tcs';;
   'x86_64')   MACHINE='gpc';;
   *)          MACHINE='unknown';;

esac

if [ "${MACHINE}" == "tcs" ] then

       # do things for the TCS machine
       alias llq1='/xcat/tools/tcs-scripts/LL/jobState.sh'
       alias llstat='/xcat/tools/tcs-scripts/LL/jobSummary.sh'
       if [ "${TERM}" = "xterm-color" ]; then
               export TERM=xterm
       fi
       # user environment for login shells goes here
       # replace colon with your own commands
       :

elif [ "${MACHINE}" == "p7" ] then

       # do things for the P7 machine
       # user environment for login shells goes here
       # replace colon with your own commands
       :

elif [ "${MACHINE}" == "gpc" ] then

       # do things for the GPC machine
       # user environment for login shells goes here
       # replace colon with your own commands
       :

else

  echo "Not a recognized system"

fi

PS1="\h-\$ "


if [ -f ~/.bashrc ]; then

      . ~/.bashrc

fi </source>

.bashrc <source lang="bash"> if [ -f /etc/bashrc ]; then

      . /etc/bashrc

fi

  1. commands which work for both GPC and TCS can go here

export BASH_ENV=~/.bashrc

  1. what machine/architecture

HOSTNAME=$(hostname) case $(uname -p) in

   'ppc64')    MACHINE='p7';;
   'powerpc')  MACHINE='tcs';;
   'x86_64')   MACHINE='gpc';;
   *)          MACHINE='unknown';;

esac

if [ "${MACHINE}" == "tcs" ] then

       # do things for the TCS machine
       # user environment for all shells goes here
       # replace colon with your own commands
       :

elif [ "${MACHINE}" == "p7" ] then

       # do things for the P7 machine
       module load pe vacpp xlf
       # user environment for all shells goes here
       # replace colon with your own commands
       :

elif [ "${MACHINE}" == "gpc" ] then

       # do things for the GPC machine
       module load intel openmpi
       # user environment for all shells goes here
       # replace colon with your own commands
       :

else

       echo "Not a recognized system"

fi </source>