Difference between revisions of "Important .bashrc guidelines"
Line 31: | Line 31: | ||
</source> | </source> | ||
− | ===Default .bashrc | + | ===Default .bashrc and .bash_profile=== |
The default startup scripts provided by SciNet are as follows. Certain things - like sourcing <tt>/etc/profile</tt> | The default startup scripts provided by SciNet are as follows. Certain things - like sourcing <tt>/etc/profile</tt> | ||
and <tt>/etc/bashrc</tt> are ''required'' for various SciNet routines to work! | and <tt>/etc/bashrc</tt> are ''required'' for various SciNet routines to work! | ||
+ | |||
+ | '''.bashrc''' | ||
+ | <source lang="bash"> | ||
+ | if [ -f /etc/bashrc ]; then | ||
+ | . /etc/bashrc | ||
+ | fi | ||
+ | |||
+ | # commands which work for both GPC and TCS can go here | ||
+ | |||
+ | HOST=$(uname) | ||
+ | |||
+ | if [ "${HOST}" == "AIX" ]; then | ||
+ | # do things for the TCS machine | ||
+ | # user environment for all shells goes here | ||
+ | # replace colon with your own commands | ||
+ | : | ||
+ | else | ||
+ | # do things for the GPC machine | ||
+ | |||
+ | module load intel openmpi | ||
+ | |||
+ | # user environment for all shells goes here | ||
+ | # replace colon with your own commands | ||
+ | : | ||
+ | fi | ||
+ | </source> | ||
'''.bash_profile''' | '''.bash_profile''' | ||
Line 43: | Line 69: | ||
# commands which work for both GPC and TCS can go here | # commands which work for both GPC and TCS can go here | ||
− | alias passwd='echo "Please use the SciNet portal to change | + | alias passwd='echo "Please use the SciNet portal to change password: https://por |
+ | tal.scinet.utoronto.ca/change_password"' | ||
+ | |||
+ | HOST=$(uname) | ||
+ | |||
+ | if [ "${HOST}" == "AIX" ] | ||
+ | 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 | ||
+ | : | ||
+ | else | ||
+ | # do things for the GPC machine | ||
+ | # user environment for login shells goes here | ||
+ | # replace colon with your own commands | ||
+ | : | ||
+ | |||
+ | fi | ||
+ | |||
+ | PS1="\h-\$ " | ||
+ | |||
+ | if [ -f ~/.bashrc ]; then | ||
+ | . ~/.bashrc | ||
+ | fi | ||
+ | </source> | ||
+ | |||
+ | Note that .bash_profile reads in the .bashrc, so that one in practice only has to add modify the .bashrc to load standard modules, set up aliases etc.. | ||
+ | |||
+ | ===Distinguishing machines and operating systems in .bashrc and .bash_profile=== | ||
+ | These above startup scripts work well if you only use the gpc, or the gpc and tcs. If you're also using the more specialize machines like the arc or p7 cluster, or if you're using both centos6 and centos5 nodes (e.g. related to the ATLAS project), then you can distinguish what system you are on and what operating system it is running using the following .bash_profile and .bashrc: | ||
+ | |||
+ | |||
+ | '''.bashrc''' | ||
+ | <source lang="bash"> | ||
+ | if [ -f /etc/bashrc ]; then | ||
+ | . /etc/bashrc | ||
+ | fi | ||
+ | |||
+ | # commands which work for both GPC and TCS can go here | ||
+ | |||
+ | export BASH_ENV=~/.bashrc | ||
# what machine/architecture | # what machine/architecture | ||
Line 67: | Line 140: | ||
fi | fi | ||
− | if [ "${MACHINE}" == "tcs" ] | + | if [ "${MACHINE}" == "tcs" ] |
then | then | ||
# do things for the TCS machine | # do things for the TCS machine | ||
− | + | # user environment for all shells goes here | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | # user environment for | ||
# replace colon with your own commands | # replace colon with your own commands | ||
: | : | ||
Line 83: | Line 149: | ||
then | then | ||
# do things for the P7 machine | # do things for the P7 machine | ||
− | # user environment for | + | |
+ | module load pe vacpp xlf | ||
+ | |||
+ | # user environment for all shells goes here | ||
# replace colon with your own commands | # replace colon with your own commands | ||
: | : | ||
Line 89: | Line 158: | ||
then | then | ||
# do things for the GPC machine | # do things for the GPC machine | ||
− | # user environment for | + | |
+ | module load intel openmpi | ||
+ | |||
+ | # user environment for all shells goes here | ||
# replace colon with your own commands | # replace colon with your own commands | ||
: | : | ||
− | # os specific commands next | + | |
+ | # os specific commands/modules can be loaded next | ||
if [ "${OS}" == "centos5" ] | if [ "${OS}" == "centos5" ] | ||
then | then | ||
− | #centos 5 specific | + | #centos 5 specific modules |
: | : | ||
elif [ "${OS}" == "centos6" ] | elif [ "${OS}" == "centos6" ] | ||
then | then | ||
− | #centos 6 specific | + | #centos 6 specific modules |
: | : | ||
fi | fi | ||
− | |||
− | |||
− | |||
− | + | else | |
− | + | echo "Not a recognized system" | |
− | |||
− | |||
− | |||
fi | fi | ||
</source> | </source> | ||
− | '''. | + | '''.bash_profile''' |
<source lang="bash"> | <source lang="bash"> | ||
− | if [ -f /etc/ | + | if [ -f /etc/profile ]; then |
− | . /etc/ | + | . /etc/profile |
fi | fi | ||
# commands which work for both GPC and TCS can go here | # 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"' | |
# what machine/architecture | # what machine/architecture | ||
Line 146: | Line 213: | ||
fi | fi | ||
− | if [ "${MACHINE}" == "tcs" ] | + | if [ "${MACHINE}" == "tcs" ] |
then | then | ||
# do things for the TCS machine | # do things for the TCS machine | ||
− | # user environment for | + | 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 | # replace colon with your own commands | ||
: | : | ||
Line 155: | Line 229: | ||
then | then | ||
# do things for the P7 machine | # do things for the P7 machine | ||
− | + | # user environment for login shells goes here | |
− | |||
− | |||
− | # user environment for | ||
# replace colon with your own commands | # replace colon with your own commands | ||
: | : | ||
Line 164: | Line 235: | ||
then | then | ||
# do things for the GPC machine | # do things for the GPC machine | ||
− | + | # user environment for login shells goes here | |
− | |||
− | |||
− | # user environment for | ||
# replace colon with your own commands | # replace colon with your own commands | ||
: | : | ||
− | + | # os specific commands next | |
− | # os specific commands | ||
if [ "${OS}" == "centos5" ] | if [ "${OS}" == "centos5" ] | ||
then | then | ||
− | #centos 5 specific | + | #centos 5 specific login commands |
: | : | ||
elif [ "${OS}" == "centos6" ] | elif [ "${OS}" == "centos6" ] | ||
then | then | ||
− | #centos 6 specific | + | #centos 6 specific login commands |
: | : | ||
fi | fi | ||
+ | else | ||
+ | echo "Not a recognized system" | ||
+ | fi | ||
− | + | PS1="\h-\$ " | |
− | + | ||
+ | if [ -f ~/.bashrc ]; then | ||
+ | . ~/.bashrc | ||
fi | fi | ||
</source> | </source> |
Revision as of 10:21, 20 October 2012
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 and .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!
.bashrc <source lang="bash"> if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
- commands which work for both GPC and TCS can go here
HOST=$(uname)
if [ "${HOST}" == "AIX" ]; then
# do things for the TCS machine # user environment for all shells goes here # replace colon with your own commands :
else
# do things for the GPC machine
module load intel openmpi
# user environment for all shells goes here # replace colon with your own commands :
fi </source>
.bash_profile <source lang="bash"> if [ -f /etc/profile ]; then
. /etc/profile
fi
- commands which work for both GPC and TCS can go here
alias passwd='echo "Please use the SciNet portal to change password: https://por tal.scinet.utoronto.ca/change_password"'
HOST=$(uname)
if [ "${HOST}" == "AIX" ] 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 :
else
# do things for the GPC machine # user environment for login shells goes here # replace colon with your own commands :
fi
PS1="\h-\$ "
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi </source>
Note that .bash_profile reads in the .bashrc, so that one in practice only has to add modify the .bashrc to load standard modules, set up aliases etc..
Distinguishing machines and operating systems in .bashrc and .bash_profile
These above startup scripts work well if you only use the gpc, or the gpc and tcs. If you're also using the more specialize machines like the arc or p7 cluster, or if you're using both centos6 and centos5 nodes (e.g. related to the ATLAS project), then you can distinguish what system you are on and what operating system it is running using the following .bash_profile and .bashrc:
.bashrc
<source lang="bash">
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
- commands which work for both GPC and TCS can go here
export BASH_ENV=~/.bashrc
- what machine/architecture
HOSTNAME=$(hostname) case $(uname -p) in
'ppc64') MACHINE='p7';; 'powerpc') MACHINE='tcs';; 'x86_64') MACHINE='gpc';; *) MACHINE='unknown';;
esac
if uname -r | grep -q el5 then
OS='centos5'
elif uname -r | grep -q el6 then
OS='centos6'
elif uname -o | grep -q AIX then
OS='aix'
else
OS='unknown'
fi
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 : # os specific commands/modules can be loaded next if [ "${OS}" == "centos5" ] then #centos 5 specific modules : elif [ "${OS}" == "centos6" ] then #centos 6 specific modules : fi
else
echo "Not a recognized system"
fi </source>
.bash_profile <source lang="bash"> if [ -f /etc/profile ]; then
. /etc/profile
fi
- 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"'
- what machine/architecture
HOSTNAME=$(hostname) case $(uname -p) in
'ppc64') MACHINE='p7';; 'powerpc') MACHINE='tcs';; 'x86_64') MACHINE='gpc';; *) MACHINE='unknown';;
esac
if uname -r | grep -q el5 then
OS='centos5'
elif uname -r | grep -q el6 then
OS='centos6'
elif uname -o | grep -q AIX then
OS='aix'
else
OS='unknown'
fi
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 : # os specific commands next if [ "${OS}" == "centos5" ] then #centos 5 specific login commands : elif [ "${OS}" == "centos6" ] then #centos 6 specific login commands : fi
else
echo "Not a recognized system"
fi
PS1="\h-\$ "
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi </source>