add non interactive logging in load.sh

can load aliases via env variable
master
David Kebler 2020-11-27 09:59:16 -08:00
parent cae3a94dd8
commit ffecdd9501
4 changed files with 22 additions and 5 deletions

View File

@ -21,7 +21,7 @@ function function_list() {
done done
echo "${FUNCS[@]}" echo "${FUNCS[@]}"
else else
cp# will list all sourced/declared functions available # will list all sourced/declared functions available
echo echo
echo -e "\033[1;4;32m""Functions:""\033[0;34m" echo -e "\033[1;4;32m""Functions:""\033[0;34m"
declare -F | grep -v "declare -f\s_" | awk {'print $3'} declare -F | grep -v "declare -f\s_" | awk {'print $3'}

15
load.sh
View File

@ -1,5 +1,15 @@
#!/bin/bash #!/bin/bash
# [[ ! $- == *i* ]] && exec >> ~/logs/load.log && exec 2>&1
function nilog () {
[[ ! $- == *i* ]] && echo -e "-----\n $USER $*" &>> ~/logs/load.log
}
nilog "called load.sh $(date)"
# nilog caller: $(caller)
# nilog pid: $(ps -o comm= $PPID)
# don't bother if bash is not the shell # don't bother if bash is not the shell
[ ! "$SHELL" = "/bin/bash" ] && return 1 [ ! "$SHELL" = "/bin/bash" ] && return 1
@ -18,6 +28,8 @@ DIR=${1:-$(dirname ${BASH_SOURCE[0]})}
module_load file module_load file
[[ $? -ne 0 ]] && echo unable to access the file module, aboarting load && return 1 [[ $? -ne 0 ]] && echo unable to access the file module, aboarting load && return 1
([[ $BASH_ENV ]] && [[ ! $- == *i* ]] && [[ $BASH_USE_ALIAS ]]) && shopt -s expand_aliases
function shell_process_directory () { function shell_process_directory () {
local SUBDIRS local SUBDIRS
local DIR local DIR
@ -53,11 +65,10 @@ function shell_process_directory () {
local SUBDIRS local SUBDIRS
local IGNORE_FILE local IGNORE_FILE
SUBDIRS=$([[ -f "$DIR/.bash-shell-include" ]] && cat "$DIR/.bash-shell-include" || echo $BASH_SHELL_BASE_SUBDIRS) SUBDIRS=$([[ -f "$DIR/.bash-shell-include" ]] && cat "$DIR/.bash-shell-include" || echo $BASH_SHELL_BASE_SUBDIRS)
[[ $SSH_LOGIN ]] && SUBDIRS+=" ssh" [[ $SSH_SESSION ]] && SUBDIRS+=" ssh"
IGNORE_FILE="$([[ -f "$DIR/.bash-shell-ignore" ]] && echo "$DIR" || echo "$BASH_SHELL_BASE")/.bash-shell-ignore" IGNORE_FILE="$([[ -f "$DIR/.bash-shell-ignore" ]] && echo "$DIR" || echo "$BASH_SHELL_BASE")/.bash-shell-ignore"
for SUBDIR in $SUBDIRS; do for SUBDIR in $SUBDIRS; do
if [ -e "$DIR/$SUBDIR" ]; then if [ -e "$DIR/$SUBDIR" ]; then
# echo processing subdirectory $DIR/$SUBDIR # echo processing subdirectory $DIR/$SUBDIR
# must quote all globs to avoid bash glob expansion which is likely on # must quote all globs to avoid bash glob expansion which is likely on
# TODO have default set of ignores plus check for .shell-ignore # TODO have default set of ignores plus check for .shell-ignore

View File

@ -11,5 +11,4 @@ if ([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]); then
export SSH_SESSION=true export SSH_SESSION=true
source /etc/profile source /etc/profile
fi fi
shopt -s expand_aliases
source $BASH_SHELL_LOAD source $BASH_SHELL_LOAD

View File

@ -33,7 +33,13 @@ export BASH_SHELL_LOAD=$BASH_SHELL_BASE/load.sh # load.sh is default
export BASH_SHELL_STARTUP=$BASH_SHELL_BASE/startup.sh # strtup.sh is default export BASH_SHELL_STARTUP=$BASH_SHELL_BASE/startup.sh # strtup.sh is default
# if uncommented next line sets up implicit sourcing for non-interactive shells # if uncommented next line sets up implicit sourcing for non-interactive shells
# export BASH_ENV=$BASH_SHELL_LOAD # use base repo # echo ----NON_INTERACTIVE SHELL INFO-----
# echo enabling bash shell repos for non-inactive shell
export BASH_ENV=$BASH_SHELL_LOAD # use base repo
# echo enabling aliases with non-interactive shell
export BASH_USE_ALIAS=true # will source aliases for non-interactive
# echo see $BASH_SHELL_BASE/shell.env
# echo ---------
# if not using implicit sourcing for non-interactive shells then on can do this per script # if not using implicit sourcing for non-interactive shells then on can do this per script
################## ##################
# expanding aliases is optional # expanding aliases is optional
@ -43,6 +49,7 @@ export BASH_SHELL_STARTUP=$BASH_SHELL_BASE/startup.sh # strtup.sh is default
# shopt -u expand_aliases # shopt -u expand_aliases
#################### ####################
# set ssh session if non-interactive only
([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]) && export SSH_SESSION=true ([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]) && export SSH_SESSION=true
# identify a network name that this host resides on # identify a network name that this host resides on