Bash
bashrc
umask 0002
export EDITOR="emacs" export HISTSIZE=100000 export history_control=ignoredups export MANPAGER=less
unset LS_COLORS unset TZ
# Test if shell is interactive case "$-" in
- i*)
- # Options alias grep='grep --color=auto' alias hg='/appl/mercurial/hg' alias nano='nano -w'
# if "${EUID}" == 0 ; then # alias ssh='ssh -CY' # alias s="echo \"Executing su - $@\"; su - $@" # else # alias ssh='ssh -ACY' # fi #alias wget='wget -c' #alias ping='ping -c10' alias ls='ls --color=auto' alias ll='ls -alrt --color' alias dire='ls -lrth' alias ..='cd ..' # Typos alias cd..='cd ..' alias xs='cd' # special hosts alias scgate='ssh scgate' alias schp01='ssh schp01' alias schp02='ssh schp02' alias schp03='ssh schp04' alias schp04='ssh schp04' # abbreviations alias ll='ls -alrt --color' alias e='echo -e'
alias p='ps -AlFwww --forest' # Features and functions alias top='unset top_skip; for a in $(eval echo {1..${LINES}}); do top_skip="${top_skip}\n"; done; echo -e ${top_skip}; unset top_skip; top -H -n1000 -c' b(){
- unset NUMARGS NONNUMARGS for ARG in $@; do
if ${ARG} =~ ^[0-9]+$; then
- NUMARGS="${NUMARGS} ${ARG}"
[ "${ARG}" = "-m" ] && NONNUMARGS="${NONNUMARGS} -u all -a" NONNUMARGS="${NONNUMARGS} ${ARG}"
- NONNUMARGS="-w ${NONNUMARGS}"
- # The last non-numeric argument is -m this can only be wrong # Therefore I use ${HOSTNAME} as additional argument if I am on a host where /opt/LSF/bin/bjobs is executable NONNUMARGS="${NONNUMARGS} ${HOSTNAME}"
- /opt/LSF/bin/bjobs ${ARGS}
- ssh scacc1 /opt/LSF/bin/bjobs ${ARGS}
- for FILE in $@; do
- if [ -r "${FILE}" ]; then
- if [ "$(awk 'BEGIN{l=0}; {l+=1}; END{print l}' ${FILE})" -gt "$((LINES-LINES/10))" ]; then
- less ${FILE}
- cat ${FILE}
- if [ "$(awk 'BEGIN{l=0}; {l+=1}; END{print l}' ${FILE})" -gt "$((LINES-LINES/10))" ]; then
- else
echo ERROR: File \""${FILE}"\" is not readable. 1>&2
- if [ -r "${FILE}" ]; then
- local arg arg="${1}" # Strip username
if echo "${arg}" | grep -q '@' && finger $(echo "${arg}" | awk -F'@' '{print $1}') 2>&1 | grep -v ": no such user." 1>/dev/null; then
- arg=$(echo "${arg}" | cut -d'@' -f 2-)
if echo "${arg}" | grep -q ':' && f_ping $(echo "${arg}" | awk -F':' '{print $1}') 2>/dev/null; then
- arg=$(echo "${arg}" | cut -d':' -f 2-)
arg="$(eval ls -d ${arg} 2>/dev/null)"
- arg="$(dirname "${arg}")"
- cd "${arg}"
- cd $@
- du -h --max-depth=1 $@
- local ARGS if [ $# -eq 0 ]; then
- ARGS="${USER}"
- ARGS="$@"
finger ${ARGS} 2>&1 | grep -v ": no such user." || grep ${ARGS} /etc/passwd
alias l 2>/dev/null 1>&2 && unalias l l(){
- ls -alrt --color $@ | tail -n $((LINES-LINES/10))
- local NEDITFILES NEDITFILES NEDITWHICH
local NEDIT=${NEDIT:=/applbin/nedit} [ -x ${NEDIT} ] || NEDIT="$(which nedit)" [ -x ${NEDIT} ] || NEDIT="/shared/appl/opensoft/Linux/nedit/bin/nedit" for NEDITARG in $@; do
- if [ -r "${NEDITARG}" ]; then
- NEDITFILES="${NEDITFILES} ${NEDITARG}"
elif which ${NEDITARG} 1>/dev/null 2>&1; then
- NEDITFILES="${NEDITFILES} $(which ${NEDITARG})"
- NEDITFILES="${NEDITFILES} ${NEDITARG}"
${NEDIT} ${NEDITFILES} &
- if [ -r "${NEDITARG}" ]; then
- tail -n $((LINES-LINES/10)) $@
- for a in $@; do
strace -p ${a} 2>&1 | head -n $((LINES-LINES/10))
- date "+%F_%T"
- for KC in /usr/bin/keychain ${HOME}/bin/keychain; do
- if [ -x "${KC}" ]; then
- break
- for KEY in ${HOME}/.ssh/id_dsa ${HOME}/.ssh/id_rsa; do
- if [ -r "${KEY}" ];then
- eval $(${KC} $@ --lockwait 120 --attempts 10 --timeout 8928 -q --eval ${KEY})
- if [ -r "${KEY}" ];then
- if [ -x "${KC}" ]; then
ping -c1 ${1} 1>/dev/null || ping -c2 ${1} 1>/dev/null || ping -c3 ${1} 1>/dev/null
- if [ ${1} ]; then
- user=${1}
- user=all
for a in $(bjobs -q error -u ${user} | awk '{if ( $1 ~ /[0-9]/ && $3 ~/PEND/) {print $1}}'); do
- bswitch $(bhist -l ${a} | gj -ofd=' ' -keys=firstqueue) ${a}
- if [ "${1}" ]; then
- echo "using ${1} as DEAD_WORKSTATION" DEAD_WORKSTATION="${1}" shift
- echo usage: f_bswitch_from_user_if_ws_pings DEAD_WORKSTATION AFFECTED_USER return 1
- AFFECTED_USER="${1}" shift
until ping -c2 ${DEAD_WORKSTATION} >/dev/null 2>&1; do
sleep ${a} && ((a++))
done && f_bswitch_error_to_firstqueue ${AFFECTED_USER} unset DEAD_WORKSTATION AFFECTED_USER a
if -n $1 ; then
- local removed=$1
while ${removed} == *//* ; do
- removed=${removed//\/\///}
- local removed=$1
- ts_of_youngest_file=0 for a in *; do
ts="$(date +%s --date="$(stat -L -c %y ${a})")" && [ "${ts}" -gt "${ts_of_youngest_file}" ] && ts_of_youngest_file=${ts}
- echo sleep $[$[5*60*60]-${age_of_youngest_file}+10]
/shared/appl/tools/beta/vwhpc_debug_job 1>&2 if tail -n1 JOB_OUTPUT.1383924.Radth-Vect-coupling | grep -q 'Waiting for'; then
- echo bkill it
- local srcdir local x local y local myfail local tar_opts=""
[ -z "$*" ] && die "Nothing passed to the 'unpack' command" for x in "$@"; do
vecho ">>> Unpacking ${x} to ${PWD}" y=${x%.*} y=${y##*.}
if ${x} == "./"* ; then
- srcdir=""
elif ${x} == ${DISTDIR%/}/* ; then
- die "Arguments to unpack() cannot begin with \${DISTDIR}."
elif ${x} == "/"* ; then
- die "Arguments to unpack() cannot be absolute"
- srcdir="${DISTDIR}/"
! -s ${srcdir}${x} && die "${x} does not exist" myfail="failure unpacking ${x}" case "${x##*.}" in
- tar)
tar xof "${srcdir}${x}" ${tar_opts} || die "$myfail" ;;
tar xozf "${srcdir}${x}" ${tar_opts} || die "$myfail" ;;
- bzip2 -dc "${srcdir}${x}" | tar xof - ${tar_opts} assert "$myfail" ;;
unzip -qo "${srcdir}${x}" || die "$myfail" ;;
- if [ "${y}" == "tar" ]; then
tar zoxf "${srcdir}${x}" ${tar_opts} || die "$myfail"
gzip -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
- if [ "${y}" == "tar" ]; then
- bzip2 -dc "${srcdir}${x}" | tar xof - ${tar_opts} assert "$myfail"
bzip2 -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
- local my_output my_output="$(7z x -y "${srcdir}${x}")" if [ $? -ne 0 ]; then
echo "${my_output}" >&2 die "$myfail"
unrar x -idq -o+ "${srcdir}${x}" || die "$myfail" ;;
lha xfq "${srcdir}${x}" || die "$myfail" ;;
ar x "${srcdir}${x}" || die "$myfail" ;;
- # Unpacking .deb archives can not always be done with
# ar. For instance on AIX this doesn't work out. If # we have deb2targz installed, prefer it over ar for # that reason. We just make sure on AIX deb2targz is # installed. if type -P deb2targz > /dev/null; then
deb2targz "${srcdir}/${x}" || die "$myfail" mv "${srcdir}/${x/.deb/.tar.gz}" data.tar.gz
ar x "${srcdir}/${x}" || die "$myfail"
- if [ "${y}" == "tar" ]; then
- lzma -dc "${srcdir}${x}" | tar xof - ${tar_opts} assert "$myfail"
lzma -dc "${srcdir}${x}" > ${x%.*} || die "$myfail"
- )
- vecho "unpack ${x}: file format not recognized. Ignoring." ;;
- ${XARGS} -0 chmod -fR a+rX,u+w,g-w,o-w
- if [ -r "${HOME}/.Xauthority" ]; then
- export XAUTHORITY=${HOME}/.Xauthority_${RANDOM}_${$} cp -pr ${HOME}/.Xauthority ${XAUTHORITY} chmod go+r ${XAUTHORITY}
if "${EUID}" == 0; then
- echo \"Executing su - $@\" su - $@
- if [ -f /opt/vw/local/scr/su_user ]; then
if [ -z "${1}" ] || finger "${1}" 2>&1 | grep -q ": no such user." ; then
SUDO_USER="$(/opt/LSF/bin/bjobs -w -u all -r -m ${HOSTNAME} 2>/dev/null | awk '/RUN/{print $2; exit}')" echo "No User provided guessing it: ${SUDO_USER}"
#
- unset NUMARGS NONNUMARGS for ARG in $@; do
- # Options alias grep='grep --color=auto' alias hg='/appl/mercurial/hg' alias nano='nano -w'
- for I in blsload bexec bpwd clocate bhwcheck bres; do
- eval alias $I=\'ssh scacc1 /opt/vw/bin/$I\'
- evebe919|wsntbk02*)
- for I in blsload bexec bpwd clocate bhwcheck bres; do
- eval alias $I=\'ssh scacc1 /opt/vw/bin/$I\'
- alias ssh="f_keychain; ssh -AY" alias scp="f_keychain; scp -p" alias bsub="ssh scacc1 /opt/LSF/bin/bsub -P0OS3170"
- g(){
- if [ "$#" -eq "0" ]; then
PIDS=$(ps -AlFwww | awk '{if ($2 == "R" && $3 !~ /root/ && $15 !~ /pts/) {print $0 > "/dev/stderr"; print $4}}')
- PIDS="$@"
- taskset -cp ${PID} gstack ${PID}
- mv2ws_error="(${USER}@${HOSTNAME}) ERROR in function f_mv2ws:" if [ $# -eq 0 ]; then
echo "$(f_date) ${mv2ws_error} a filename to copy needs to be provided" 1>&2 return 1
- MV2DIRARGS="${MV2DIRARGS} -k" shift
echo "$(f_date) ${mv2ws_error} The variable JOB_WSOUTDIR is empty." 1>&2 return 2
- if [ -n "${JOB_WSNAME:-}" -a -n "${JOB_WSUSER:-}" ]; then
- TARGET="${JOB_WSUSER}@${JOB_WSNAME}:${JOB_WSOUTDIR}"
echo "$(f_date) ${mv2ws_error} could not set TARGET correctly" 1>&2 echo "$(f_date) ${mv2ws_error} JOB_WSUSER=\"${JOB_WSUSER}\" JOB_WSNAME=\"${JOB_WSNAME}\" JOB_WSOUTDIR=\"${JOB_WSOUTDIR}\"" 1>&2 return 3
- MV2DIRARGS="${MV2DIRARGS} -s"
- if [ -r "${FILE}" ]; then
[ "${JOB_WSGROUPW}" = 'yes' ] && chmod g+w ${FILE} /opt/vw/bin/mv2dir ${MV2DIRARGS} ${TARGET} ${FILE}
- if [ -z "${JOB_WSNAME}" -o -z "${JOB_WSOUTDIR}" -o -z ${JOB_WSUSER} ]; then
echo "A required variable is empty" 1>&2 echo -e "JOB_WSUSER=\"${JOB_WSUSER}\"\tJOB_WSNAME=\"${JOB_WSNAME}\"\tJOB_WSOUTDIR=\"${JOB_WSOUTDIR}\"" 1>&2 return 1
- echo "cd ${JOB_WSOUTDIR}" ssh ${JOB_WSUSER}@${JOB_WSNAME}
- ssh ${JOB_WSUSER}@${JOB_WSNAME} "cd ${JOB_WSOUTDIR}; $@"
- if [ "$#" -eq "0" ]; then
echo "You have to provide a command to execute" 1>&2
echo "A required varable is empty" 1>&2 echo -e "HOSTNAME=\"${HOSTNAME}\"\JOB_HOSTLIST=\"${JOB_HOSTLIST}\"\JOB_BATCHDIR=\"${JOB_BATCHDIR}\"" 1>&2
- # Try to figure out if remote noninteractive execution will work
- if [ "$#" -eq "0" ]; then
- for I in blsload bexec bpwd clocate bhwcheck bres; do
# if ALIAS=$(alias ${1}) 2>/dev/null; then # ${1}="${ALIAS} " # fi # unset ALIAS
- for JOB_HOST in ${JOB_HOSTLIST}; do
- if [ ${JOB_HOST} != ${HOSTNAME} ]; then
- ssh -AY ${JOB_HOST} "cd ${JOB_BATCHDIR}; $@"
- if [ ${JOB_HOST} != ${HOSTNAME} ]; then
- else
echo "The command \"$@\" failed to execute locally. No remote execution will be performed" 1>&2
- } for I in blsload bexec bpwd clocate bhwcheck bres; do
- eval unalias ${I}
- alias bsub="bsub -P0OS3170"
if which bjoblog 2>/dev/null 1>&2; then
- alias bjob="bjobs"
JOB_BATCHDIR=$(ls -ld /tmp/BATCH.${USER}.${LSB_JOBID:=*} 2>/dev/null | awk '/\/tmp\/BATCH.'${USER}'/{print $NF; exit}') if [ "${JOB_BATCHDIR}" ]; then
- if [ -r "${JOB_BATCHDIR}/.env" ]; then
- # We are on the first node source ${JOB_BATCHDIR}/.env
LSB_JOBID=${LSB_JOBID:=$(ls -ld /tmp/BATCH.${USER}.* 2>/dev/null | awk -F'/' '{print $(NF-1)}' | awk -F'.' '{print $NF; exit}')} #' FIRSTHOST=$(/opt/LSF/bin/bjobs ${LSB_JOBID} | awk '/RUN/ {print $6}' | awk -F'*' '{print $2}') JOB_ENV="/hosts/${FIRSTHOST}/$(echo ${JOB_BATCHDIR} | awk -F'/' '{print $3}')/.env" source ${JOB_ENV} || echo "Could not source JOB_ENV=\"${JOB_ENV}\" . "
- # RT: source ${JOB_APPL_FUNCTIONS} for interactive usage source ${JOB_APPL_FUNCTIONS}
- ;; e?ebe*)
- for CMD in bacct bhosts bjobs bhist lshosts bstop bresume brequeue bswitch brun bkill bqueues bmod btop bbot bpeek bjdepinfo lsload ; do
- if [ -x /opt/LSF/bin/${CMD} ]; then
- eval alias ${CMD}=/opt/LSF/bin/${CMD}
- eval alias ${CMD}=\'ssh scacc1 /opt/LSF/bin/${CMD}\'
- alias bsub="/opt/LSF/bin/bsub -P0OS3170"
- alias bsub="ssh scacc1 /opt/LSF/bin/bsub -P0OS3170"
- if [ -x /opt/LSF/bin/${CMD} ]; then
- for CMD in bacct bhosts bjobs bhist lshosts bstop bresume brequeue bswitch brun bkill bqueues bmod btop bbot bpeek bjdepinfo lsload ; do
- ) ;;
- esac # recreate the contents of this file by starting as root@cae-support
# ssh hpcappl@scacc1 "env ENV=/opt/vw/etc/kshrc KSHRC_IFLAG=1 /bin/ksh -c set" | grep ^SC > /appl/tools/beta/vwhpc.hosts for HOSTLIST in /shared/appl/tools/beta/vwhpc.hosts /appl/tools/beta/vwhpc.hosts ~/.vwhpc.hosts; do
- if [ -r "${HOSTLIST}" ]; then
source ${HOSTLIST} && break
- eval alias ${I}=\'ssh ${I}\'
- if [ -r "${HOSTLIST}" ]; then
# if ${EUID} == 0 ; then # export PS1='\[\033[1;33m\]\t \[\033[1m\]\[\033[1;31m\]\h:\[\033[1;34m\]\w \$\[\033[00m\] ' # else
- # create coloured bash prompt # black background PS1="\[\033[1;40m\]" # yellow time PS1="${PS1}\[\033[1;33m\]\d \t" case ${USER} in
- fox0fdn)
- # green PS1="${PS1} \[\033[1;32m\]\u"
- # red PS1="${PS1} \[\033[1;31m\]\u"
- )
- # light blue PS1="${PS1} \[\033[1;36m\]\u"
- case ${HOSTNAME} in
- wsntbk02*)
- # reset to black background and green hostname (no username) PS1="\[\033[1;40m\]\[\033[1;33m\]\t "
if "${EUID}" == 0; then
- # red PS1="${PS1}\[\033[1;31m\]\h"
- # green PS1="${PS1}\[\033[1;32m\]\h"
- # green PS1="${PS1}\[\033[1;32m\]\h"
- # reset to black background and green hostname (no username) PS1="\[\033[1;40m\]\[\033[1;33m\]\t "
- wsntbk02*)
- fox0fdn)
# export PATH=~/jgen/bin/:$PATH
- ;; evebe777|evebe759)
- # red PS1="${PS1}\[\033[1;31m\]\h"
- # white PS1="${PS1}\[\033[1;37m\]\h"
- # white PS1="${PS1}\[\033[1;35m\]\h"
- # light blue PS1="${PS1}\[\033[1;36m\]\h" unset brun bjobs
- # light blue PS1="${PS1}\[\033[1;36m\]\h"
- )
- # pink PS1="${PS1}\[\033[1;35m\]\h"
- esac export PS1="${PS1}\[\033[1;30m\]:\[\033[1;34m\]\w \$\[\033[00m\] "
# fi
- ;;
- ) : # This shell is not interactive ;;
esac
#if [ "${USER}" = "etorabi" -a "${HOSTNAME}" = "evebe700" ]; then # unalias s 2>/dev/null # s(){ # echo "executing \"sudo su - $@ /opt/vw/shared/appl/tools/beta/etorabi\"" 1>&2 # sudo su - $@ /opt/vw/shared/appl/tools/beta/etorabi # } #fi bjur(){
- delay='60'
[ $# -gt 1 ] && delay="$2" while :; do
- clear
echo "Updated at "date +%H:%M:%S bjobs -u $1 sleep $delay
- clear
}
bjud() {
- delay='60'
[ $# -gt 1 ] && delay="$2" while :; do
- clear
echo "Updated at "date +%H:%M:%S bjobs -u $1 -d | tail -n 50 sleep $delay
- clear
}
bju() {
- delay='60'
[ $# -gt 1 ] && delay="$2" while :; do
- clear
echo "Updated at "date +%H:%M:%S bjobs -u $1 echo ".-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-.-'-" bjobs -u $1 -d | tail -n 50 sleep $delay
- clear
}
bjq() {
- delay='60'
[ $# -gt 1 ] && delay="$2" while :; do
- clear
echo "Updated at "date +%H:%M:%S bjobs -q $1 -u all echo bjobs -q $1 -u all -d | tail -n 50 sleep $delay
- clear
}
# support colors in less export LESS_TERMCAP_mb=$'\E[01;31m' export LESS_TERMCAP_md=$'\E[01;31m' export LESS_TERMCAP_me=$'\E[0m' export LESS_TERMCAP_se=$'\E[0m' export LESS_TERMCAP_so=$'\E[01;44;33m' export LESS_TERMCAP_ue=$'\E[0m' export LESS_TERMCAP_us=$'\E[01;32m'