Skip to content

Commit

Permalink
Several enhancements and version update to 2024-08-23 (#33)
Browse files Browse the repository at this point in the history
* Allow debugging using PS4 and "set -x" via "--debug"

* Rewrite Prompts using PROMPT_COMMAND variable

* Enhance grplogs to allow scanning gz-compressed logs

* Update version date

---------

Co-authored-by: Jan Schnackenberg <[email protected]>
  • Loading branch information
JanSchnacki and Jan Schnackenberg authored Aug 23, 2024
1 parent fb23c77 commit 251c848
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions ocenv
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/usr/bin/env bash

## Allow debugging of script, including line-number information and runtime-information
## We use "²" as delimiter, to allow separation of the output (e.g. in Excel)
if [[ "$1" == --debug ]]
then
export PS4='+ ²$(date "+%s.%N")²$LINENO² '
set -x
fi

# Bash script to configure the environment for an Oracle DBA
# Copyright (C) 2021 OPITZ CONSULTING Deutschland GmbH
#
Expand Down Expand Up @@ -31,7 +39,7 @@
################################################################################

## Version of this script. Simply uses the date in YYYY-MM-DD format
GV_OCENV_VERSION="2023-12-10"
GV_OCENV_VERSION="2024-08-23"

###############################################################################
## Environment support homogenization
Expand Down Expand Up @@ -420,21 +428,18 @@ if [[ "${GV_TTY}" -eq 0 ]]
then
# enclose unprintable parts in "\[" and "\]" to tell bash that they do not affect the lenght of the prompt
## Variables used in PS1 and PS2 have \[ and \] to correct width-calculation of prompt
GV_P_T_RED="$(printf "\[%s\]" "${GV_T_RED}")"
GV_P_T_GREEN="$(printf "\[%s\]" "${GV_T_GREEN}")"
GV_P_T_WHITE="$(printf "\[%s\]" "${GV_T_WHITE}")"
GV_P_B_BOLD="\[${GV_B_WHITE}\]"
GV_P_CCLR="\[${GV_CCLR}\]"

declare -a GV_ALIAS_LIST
declare -a GV_PDB_LIST
export HISTTIMEFORMAT="%F %T "
if [[ "${USER}" == "root" ]]
then
export PS1="[${GV_P_T_RED}\u${GV_P_T_WHITE}@\h] [\w]\n${GV_P_B_BOLD}#${GV_P_CCLR} "
export PROMPT_COMMAND='LAST_RETCODE=$?; builtin echo -ne "\n[${GV_T_GREEN}${USER}${GV_T_WHITE}@${HOSTNAME}] [${PWD}]"; [ $LAST_RETCODE = 0 ] && builtin echo -ne "\e[$((COLUMNS - ${#LAST_RETCODE}))G\e[1;32m${LAST_RETCODE}\e[0m\n" || builtin echo -ne "\e[$((COLUMNS - ${#LAST_RETCODE}))G\e[31m${LAST_RETCODE}\e[0m\n"'
export PS1="${GV_P_B_BOLD}#${GV_P_CCLR} "
export PS2="${GV_P_B_BOLD}#${GV_P_CCLR} "
else
export PS1="[${GV_P_T_GREEN}\u${GV_P_T_WHITE}@\h] [${GV_P_T_RED}\${ORACLE_SID}${GV_P_T_WHITE}] [\w]\n${GV_P_B_BOLD}\$${GV_P_CCLR} "
export PROMPT_COMMAND='LAST_RETCODE=$?; builtin echo -ne "\n[${GV_T_GREEN}${USER}${GV_T_WHITE}@${HOSTNAME}] [${GV_T_RED}${ORACLE_SID}${GV_T_WHITE}] [${PWD}]"; [ $LAST_RETCODE = 0 ] && builtin echo -ne "\e[$((COLUMNS - ${#LAST_RETCODE}))G\e[1;32m${LAST_RETCODE}\e[0m\n" || builtin echo -ne "\e[$((COLUMNS - ${#LAST_RETCODE}))G\e[31m${LAST_RETCODE}\e[0m\n"'
export PS1="${GV_P_B_BOLD}\$${GV_P_CCLR} "
export PS2="${GV_P_B_BOLD}\$${GV_P_CCLR} "
fi

Expand Down Expand Up @@ -1543,7 +1548,18 @@ grplogs() {
fi
local LV_REGEXP="$1"
shift
awk -v V_SEARCH_REGEX="${LV_REGEXP}" '
(
for LV_FILENAME in "$@"
do
echo "STARTING_WITH_NEW_FILE ${LV_FILENAME}"
if [[ ${LV_FILENAME} =~ ^.*\.gz$ ]]
then
gunzip --to-stdout "${LV_FILENAME}"
else
cat "${LV_FILENAME}"
fi
done
) | awk -v V_SEARCH_REGEX="${LV_REGEXP}" '
function myprint(filename, linenumber, date, line)
{
printf("%-30s [%d][%s]: %s\n", filename, linenumber, date, line);
Expand All @@ -1560,16 +1576,19 @@ grplogs() {
v_date_printed = 0;
v_date_NR = -1;
}
/^STARTING_WITH_NEW_FILE / {
v_filename=$2
}
{
if ( $0 ~ search_date_regex) {
v_date = $0;
v_date_printed = 0;
v_date_NR = NR;
} else if ( $0 ~ search_ora_regex ) {
myprint(FILENAME, NR, v_date, $0);
myprint(v_filename, NR, v_date, $0);
}
}
' "$@"
'
}
rotate_file() {
local LV_SOURCE="$1"
Expand Down

0 comments on commit 251c848

Please sign in to comment.