Bash Setup
PennSIVE Bash Startup Scripts
When you ssh
into the cluster, bash automatically sources (AKA runs) three files from your home folder: .bash_profile, .bash_aliases, and .bashrc
It is helpful/important that you include a number of commands in these files so that your environment is set up correctly, and also so you can load a number of “aliases” (ie short abbreviations for longer, commonly-used commands) into the environment.
Below are PMACS-specific bash scripts that may be useful to PennSIVE members. These files should be copied into your home folder and named the headers below. To use these startup files, you will additionally need a file named .env
, also included below.
Startup Scripts
.bash_profile
- Navigate to home folder (
cd ~
) - Create new file named .bash_profile (
touch .bash_profile
) - Open .bash_profile in text editor such as Nano (
nano .bash_profile
) - Copy paste below code block into text editor.
- Exit Nano (Ctrl+X on Mac)
# ~/.bash_profile
export QUEUE=taki
if [ -f $HOME/.bashrc ]; then
source $HOME/.bashrc
fi
export LD_LIBRARY_PATH="/home/$USER/software/pkg/mamba/lib:$LD_LIBRARY_PATH"
.bash_aliases
- Navigate to home folder (
cd ~
) - Create new file named .bash_aliases (
touch .bash_aliases
) - Open .bash_aliases in text editor such as Nano (
nano .bash_aliases
) - Copy paste below code block into text editor.
- Exit Nano (Ctrl+X on Mac)
if [[ $SHELL == "/bin/bash" ]]; then
source "$(dirname $BASH_SOURCE)/.env"
else
source "$(dirname $0)/.env"
fi
export TMPDIR=/scratch
# Command aliases
alias q='exit'
alias c='clear'
alias h='history'
alias p='cat'
alias l='ls'
alias la='ls -a'
alias ll='ls -lh'
alias k='kill'
# Grid alias
alias last='last -20'
alias qs='bhosts'
alias countjobs='echo "Total"; bjobs | wc -l; echo "Running"; bjobs | grep -i run | wc -l; echo "Pending"; bjobs | grep -i pend | wc -l'
alias myhosts='bhosts | sed -n 1p ; bhosts | grep $USER'
alias myqueues='bqueues | sed -n 1p ; bqueues | grep $USER'
alias qint='bsub -Is -q taki_interactive "bash"'
alias qmatlab='bsub -Is -q matlab_interactive "bash"'
alias qstata='bsub -Is -q stata_interactive "bash"'
alias qgpu='bsub -Is -q lpcgpu -gpu "num=1" -n 1 "bash"'
alias snap="vglrun itksnap"
# Git aliases
alias gpull='git pull --all'
alias g='git'
alias gst='git status'
alias gcom='git commit -m'
alias gall='git add -A'
alias pull-submodules="git submodule foreach git pull origin master"
alias prune-branches="git remote update origin --prune"
alias force-pull="git fetch --all && git reset --hard origin/master"
#conda aliases
alias cenvs="conda info --envs"
alias cdeac="conda deactivate"
alias clist="conda list"
alias jconvert="jupyter nbconvert --to script *.ipynb"
#navigating
alias home='cd ~'
alias root='cd /'
alias dtop='cd ~/Desktop'
alias docs='cd ~/Documents'
alias ..='cd ..'
alias ...='cd ..; cd ..'
alias ....='cd ..; cd ..; cd ..;'
#program aliases
alias tar='gtar'
alias python='python3'
alias pip='pip3'
alias bashrc='vim ~/.bashrc'
alias bashaliases='vim ~/.bash_aliases'
PS1='\[\e[0;33m\]\u\[\e[0m\]@\[\e[0;32m\]\h\[\e[0m\]:\[\e[0;34m\]\w\[\e[0m\]\$ '
if [ -d /cbica ]; then
export PS1
module load neuroR/0.2.0
alias rstudio='SINGULARITYENV_PORT=${PREFERRED_PORT} singularity run -e -B $TMPDIR/$USER:/var -B $HOME:/root /cbica/home/robertft/singularity_images/rstudio_4.1.sif'
alias mrpeek='singularity run -e /cbica/home/robertft/singularity_images/mrpeek_latest.sif'
elif [ -d /project ] && [ -e /lsf ]; then
export PS1
module load DEV/singularity
alias rstudio='SINGULARITYENV_PORT=${PREFERRED_PORT} singularity run -e -B $TMPDIR/$USER:/var -B $HOME:/root /project/singularity_images/rstudio_4.1.sif'
alias spyder='SINGULARITYENV_PORT=${PREFERRED_PORT} singularity run -e -B $TMPDIR/$USER:/var -B $HOME:/root /project/singularity_images/spyder-desktop_latest.sif'
alias neuropython='singularity run -e -B $TMPDIR/$USER:/var -B $HOME:/root /project/singularity_images/neuropythy_latest.sif'
alias jlab='jupyter-lab --no-browser --port=1105'
alias mrpeek='singularity run -e /project/singularity_images/mrpeek_latest.sif'
else # local
which starship >/dev/null 2>&1 && eval "$(starship init $(basename $SHELL))" || export PS1
alias rstudio='docker run --rm -d -v $PWD:/data -w /data -p 80:8787 pennsive/rstudio:4.1'
alias mrpeek='docker run --rm -it -v $PWD:$PWD -w $PWD pennsive/mrpeek'
alias edit-spellcheck="vim ~/Library/Spelling/LocalDictionary"
alias images="docker image ls"
alias containers="docker ps -a"
alias rmi="docker rmi"
alias sublime="open -a 'Sublime Text' ."
alias openitk='open -a ITK-SNAP '
alias sizeof="du -hs"
alias cbica="ssh ${CBICA_USERNAME}@cubic-login.uphs.upenn.edu"
alias cbicax="ssh -Y ${CBICA_USERNAME}@cubic-login.uphs.upenn.edu"
alias cbicahttp="ssh -L${PREFERRED_PORT}:127.0.0.1:${PREFERRED_PORT} -q ${CBICA_USERNAME}@cubic-login.uphs.upenn.edu"
alias sciget="ssh ${PMACS_USERNAME}@sciget.pmacs.upenn.edu"
alias scisub="ssh ${PMACS_USERNAME}@scisub.pmacs.upenn.edu"
alias takim="ssh ${PMACS_USERNAME}@takim"
alias takimx="ssh -Y ${PMACS_USERNAME}@takim"
alias takimhttp="ssh -L ${PREFERRED_PORT}:127.0.0.1:${PREFERRED_PORT} -q ${PMACS_USERNAME}@takim"
alias takimhttp2="ssh -L ${PREFERRED_PORT2}:127.0.0.1:${PREFERRED_PORT2} -q ${PMACS_USERNAME}@takim"
fi
## Do Grid stuff if on submit host
MYHOST=`/bin/hostname`
#### OTHER THINGS THAT I DONT WANT TO CHANGE WHEN BASHRC IS UPDATED:
export LD_LIBRARY_PATH="/home/$USER/software/pkg/mamba/lib:/home/$USER/software/mamba/envs/:$LD_LIBRARY_PATH"
export PATH="$PATH:/commapp/matlab/bin/"
export PATH="$PATH:/appl/MIPAV"
export PATH="$PATH:/project/tapps/mricron"
export PATH="$PATH:/usr/local/cuda-5.0/bin"
export PATH="$PATH:/project/tapps/freesurfer/lib/vtk/lib/vtk-5.6"
export PATH="$PATH:/project/tapps/ants/bin"
export PATH="$PATH:/appl/MASS-1.1.0/bin"
export ANTSPATH=/project/tapps/ants/bin
# Modules
module load fsl
module load R
module load ANTs
module load DEV/singularity
module load git
module load vim
module load gcc/12.2.0
#source $HOME/software/pkg/mamba/bin/activate
#echo donemodules
# Freesurfer
export FREESURFER_HOME=/appl/freesurfer-7.1.1
export SUBJECTS_DIR=$FREESURFER_HOME/subjects
export FS_LICENSE=/home/$USER/software/freesurfer/license.txt
#source $FREESURFER_HOME/SetUpFreeSurfer.sh
# FSL
FSLDIR=/appl/fsl-6.0.3
. ${FSLDIR}/etc/fslconf/fsl.sh
PATH="$PATH:${FSLDIR}/bin"
export FSLDIR PATH
# Functions
killscreens () {
screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs kill
}
.bashrc
- Navigate to home folder (
cd ~
) - Create new file named .bash_profile (
touch .bash_profile
) - Open .bash_profile in text editor such as Nano (
nano .bash_profile
) - Copy paste below code block into text editor.
- Exit Nano (Ctrl+X on Mac)
# .bashrc
### This file is generated with the updateme/updateEnv script. You should NOT modify this file. ###
### This file will be overwritten the next time you run the updateme/updateEnv script. ###
### Please use ~/.bash_aliases for personalization of your environment. ###
### Our scripts will never overwrite .bash_aliases. ####
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
if [ -f $HOME/.bash_aliases ]; then
source $HOME/.bash_aliases
fi
# LSF. Changing this may affect your ability to submit to the grid.
source /lsf/conf/profile.lsf
### Modules
source /appl/Modules/current/init/bash
export LPC_MODULES=$(cat /appl/util/env/lpc_modules| grep -v ^#)
module load ${LPC_MODULES}
# To change your queue, please consider editing the "export QUEUE=..." line in your .bash_profile
export LSB_DEFAULTQUEUE="$QUEUE"_normal
# the presence of /usr/local/bin/ibash indicates that the shell is on
# an execute host and these functions will be disabled
if [ ! -r /usr/local/bin/ibash ] ; then
function ibash { bsub -Is -q "$QUEUE"_interactive 'bash'; }
function xbash { bsub -Is -XF -q "$QUEUE"_interactive 'bash'; }
fi
.env
The .bash_aliases file will need you to set some environment variables. We will store the environment variables in the .env
file.
- Edit below code to include your usernames. If you do not have a CBICA username, change that line to
CBICA_USERNAME=""
. Preferred port number can be any integer between 1000 and 9998. I recommend randomly choosing an integer within this range.
CBICA_USERNAME="your_cbica_username"
PMACS_USERNAME="your_pmacs_username"
PREFERRED_PORT="your_preferred_port"
PREFERRED_PORT2=$(($PREFERRED_PORT + 1))
For example, my code is:
CBICA_USERNAME="hufen"
PMACS_USERNAME="fengling"
PREFERRED_PORT="1520"
PREFERRED_PORT2=$(($PREFERRED_PORT + 1))
Then, 1. Navigate to home folder (cd ~
) 2. Create new file named .bash_profile (touch .env
) 3. Open .bash_profile in text editor such as Nano (nano .env
) 4. Copy paste below code block into text editor. 5. Exit Nano (Ctrl+X on Mac)
Source new startup scripts
- Source the new scripts by running the following command in bash (
source ~/.bash_profile; source ~/.bash_aliases; source ~/.bashrc
)