I'm trying to increase usabilty for my scripted project-, for that i wanted to apply an error message poping up upon every and any error (other than proper exit) indicating the enduser a uniform, and hopefully readable error messsage.
To achieve this, i wrote a msg_error function, and prepared some trap handling...
Code:
msg_error() { # CALLER SCRIPT FUNCNAME LINENO [CONTENT]
# Prints an error message and exits
#
caller="\$1" script="\$2" fname="\$3" lineno="\$4"
shift 4
content=($(echo "\${@}"))
printf '\r\t%s:\t%s\n' \\
"$(gettext 'Caller of script')" "\$caller" \\
"$(gettext 'Scriptname')" "\$script" \\
"$(gettext 'Functionname')" "\$fname" \\
"$(gettext 'Linenumber')" "\$lineno"
for cont in "\${content[@]}";do
printf '\t%s\n' "\$cont"
done
trap − INT QUIT TERM EXIT
exit 1
}
Code:
#
# Traps & Error messages
#
traps_save(){ saved_traps=\$(trap) ; export saved_traps ; }
traps_restore() { eval \$saved_trap;}
export -f msg_error traps_save traps_restore
# Set and save basic error message traping,
trap "msg_error \${CALLER:-$0} \$0 \${FUNCNAME:-NON-FUNCTION} \$LINENO 'Args: \$@' " HUP INT QUIT ABRT KILL ALRM TERM ## 1 2 3 6 9 14 15
traps_save # Save initial traps
My issue isnt this... well at least not really..
My issue is the follow up, when callling a script with the same name (but which is intended to be executed, while this generated script is ment to be sourced).
Code:
0 ~/prjs/tui $ export LC_ALL=C
0 ~/prjs/tui $ ./make ; sudo ./make-install ; sh ./tuirc ##(this is /etc/tuirc)
0 ~/prjs/tui $ bash -x $(which tuirc) ## (this is /bin/tuirc)
+ tui-print -H 'TUI (0.9.4-inprogress), Copyright (c) 2015 by sea' 'Simon Arjuna Erat (sea), 08:02:02 2015-12-26'
/etc/tuirc: line 129: trap: TUI (0.9.4-inprogress), Copyright (c) 2015 by sea: invalid signal specification
/etc/tuirc: line 129: trap: Simon Arjuna Erat (sea), 08:02:02 2015-12-26' : invalid signal specification
<..>
1 ~/prjs/tui $ which tuirc
/usr/bin/tuirc
So the search for one of the errrors ($'\212.... not found) became more complicated than expected...
Code:
cat -n /etc/tuirc | grep 129
129 trap "msg_error ${CALLER:-$0} $0 ${FUNCNAME:-NON-FUNCTION} $LINENO '$@'" INT QUIT TERM
## HUP INT QUIT ABRT KILL ALRM TERM ## 1 2 3 6 9 14 15
I dont understand where the invalid signal spec comes from?
Specialy since calling the /etc/tuirc script by itself, it closes without error, but sourcing from other files, it raises one, in way i cant follow the reason.
Any ideas or advices please?
Thank you in advance.
I'm confused. The title of this thread is "[BASH] Errormessages and Traps with a 'here-doc'", but I don't see any here-documents anywhere in the code you've shown us?
the standards say that setting a trap for SIGKILL produces undefined results. So you might want to try this without the KILL parameter. (There is no way for any process to catch a SIGKILL signal.)
In fact you quoted parts of the 'here-doc', but you're right it isnt obvious.
Thought it was, due to the escapes.
Also, seems i was editing my post while you wrote the answer, i've already removed the 'kill' signall, with no change.
Sorry about that.
The traps_{save,restore} arent (really) used yet (outside of that script).
As of now (past, until now), the generated ./tuirc did only contain TUI_DIR_{variables}, and the injection_protection.
Which was sourced by the already existing and hardcoded ./bin/tuirc. (which is either sourced or executed - to config, etc).
End goal is to replace the current hardcoded ./bin/tuirc with the generated ./tuirc which - as soon it works - will become the ./bin/tuirc.
But i guess this is only relevant to me.
Anyway, here's the full script: ./scripts/gen-tuirc.sh
NOTE: the commented out cat tuirc.tpl results in an endless loop, as the *tpl was not adjusted to the recent changes (it still sources 'itself' as its origin is/was bin/tuirc).
Also, all the functions/variables of the *tpl file are already present in the executed (not visible here) bin/tuirc.
Code:
#!/usr/bin/env bash
# ------------------------------------------------------------------------
# Copyright (c) 2015 Simon Arjuna Erat (sea) <erat.simon@gmail.com>
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
# ------------------------------------------------------------------------
for tc in /usr/var/tmp /var/tmp /tmp $HOME/.cache;do [ -w "$tc" ] && break;done
for tl in /usr/var/log /var/log $HOME/.config/tui/logs;do [ -w "$tc" ] && break;done
source ./tui_dirs.conf
cat << EOS
#!/usr/bin/env bash
# ------------------------------------------------------------------------
# Copyright (C) 1996-2015 Simon Arjuna Erat (sea) <erat.simon@gmail.com>
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
# ------------------------------------------------------------------------
#
# This file provides the core of the heart
#
# This project
TUI_VERSION=$(gawk -F= '/APP_VER/ {print $2}' ./configure.yassi|head -n1) # 0.9.4
# This script
TRC_VERSION=3.0
#TUI_AUTHOR="Simon Arjuna Erat (sea), Switzerland"
#
# This file is NOT meant to be changed.
#
[ -z "\$TUI_DIR_CONF" ] && readonly TUI_DIR_CONF="$SYSCONFDIR/tui"
[ -z "\$TUI_DIR_SYSTEM" ] && readonly TUI_DIR_SYSTEM="$DATADIR"
#
# Paths : Used to run TUI
#
TUI_DIR_TEMP="$tc"
TUI_DIR_LOG="$tl"
TUI_DIR_THEMES="\$TUI_DIR_SYSTEM/themes"
[ -z "\$TUI_DIR_TEMPLATES" ] && readonly TUI_DIR_TEMPLATES="\$TUI_DIR_SYSTEM/templates"
[ -z "\$TUI_DIR_FUNCTIONS" ] && readonly TUI_DIR_FUNCTIONS="\$TUI_DIR_SYSTEM/functions"
[ -z "\$TUI_DIR_LOCALE" ] && readonly TUI_DIR_LOCALE="\$TUI_DIR_SYSTEM/locale"
[ -z "\$TUI_DIR_LIST" ] && readonly TUI_DIR_LIST="\$TUI_DIR_SYSTEM/lists"
#
# Files
# Direct access to the most important configuration files for the System
#
[ -z "\$TUI_FILE_CONF_APPS" ] && readonly TUI_FILE_CONF_APPS="\$TUI_DIR_CONF/apps.conf"
[ -z "\$TUI_FILE_CONF_COLORS" ] && readonly TUI_FILE_CONF_COLORS="\$TUI_DIR_CONF/colors.conf"
[ -z "\$TUI_FILE_CONF_COMMANDS" ] && readonly TUI_FILE_CONF_COMMANDS="\$TUI_DIR_CONF/commands.conf"
[ -z "\$TUI_FILE_CONF_SETTINGS" ] && readonly TUI_FILE_CONF_SETTINGS="\$TUI_DIR_CONF/settings.conf"
[ -z "\$TUI_FILE_CONF_SYSTEM" ] && readonly TUI_FILE_CONF_SYSTEM="\$TUI_DIR_CONF/tui.conf"
[ -z "\$TUI_FILE_CONF_STATUS" ] && readonly TUI_FILE_CONF_STATUS="\$TUI_DIR_CONF/status.conf"
[ -z "\$TUI_FILE_CONF_SHORTS" ] && readonly TUI_FILE_CONF_SHORTS="\$TUI_DIR_CONF/shorts.conf"
[ -z "\$TUI_FILE_CONF_ALIAS" ] && readonly TUI_FILE_CONF_ALIAS="\$TUI_DIR_CONF/shorts-alias.conf"
#
# Low level workarounds, fallbacks and 'make sures' before the system config is read
#
HOMEBASE="$HOMEBASE" # This should provide OS independant base for regular users.
HOME="\${HOME:-\$(eval echo ~\${SUDO_USER:-\$USER})}"
TERM="\${TERM:-GNU\057Linux}"
WIDTH="\${COLUMNS:-\$(tput cols)}"
HEIGHT="\${LINES:-\$(tput lines)}"
TUI_THEME="default"
AWK=\gawk
GREP=\grep
SED=\sed
LS=\ls
#
# Color and other formatting
# Since this is also for 'endusers', this is all small letters
#
reset="\033[0m" ; invert="\033[7m"
bold="\033[1m" ; stroke="\033[9m" ; underline="\033[4m"
# --- Colors : foreground ----- Colors : background ------------
black="\033[30m" ; bg_black="\033[40m"
red="\033[31m" ; bg_red="\033[41m"
green="\033[32m" ; bg_green="\033[42m"
yellow="\033[33m" ; bg_yellow="\033[43m"
blue="\033[34m" ; bg_blue="\033[44m"
purple="\033[35m" ; bg_purple="\033[45m"
cyan="\033[36m" ; bg_cyan="\033[46m"
white="\033[37m" ; bg_white="\033[47m"
#
# Protection and Error handling
#
break_on_injections() { # ARGS
# Searches for injection subjects
# Returns true if it finds some
trap − HUP INT QUIT ABRT KILL ALRM TERM EXIT
typeset arg ac=0
for arg do
ac="$((ac+=1))"
case "$arg" in
(*[';´|<&>']*|*':('*|*':-'*)
printf "%s\n" "Aborting, injection detected! arg\${ac}='\$arg'"
return 0
;;
esac
done
trap − HUP INT QUIT ABRT ALRM TERM EXIT
return 1
}
msg_error() { # CALLER SCRIPT FUNCNAME LINENO [CONTENT]
# Prints an error message and exits
#
caller="\$1" script="\$2" fname="\$3" lineno="\$4"
shift 4
content=($(echo "\${@}"))
printf '\r\t%s:\t%s\n' \\
"$(gettext 'Caller of script')" "\$caller" \\
"$(gettext 'Scriptname')" "\$script" \\
"$(gettext 'Functionname')" "\$fname" \\
"$(gettext 'Linenumber')" "\$lineno"
for cont in "\${content[@]}";do
printf '\t%s\n' "\$cont"
done
trap − HUP INT QUIT ABRT KILL ALRM TERM EXIT
exit 1
}
#
# Traps & Error messages
#
traps_save(){ saved_traps=\$(trap) ; export saved_traps ; }
traps_restore() { eval \$saved_traps;}
export -f msg_error traps_save traps_restore
# Set and save basic error message traping,
trap "msg_error \${CALLER:-\$0} \$0 \${FUNCNAME:-NON-FUNCTION} \$LINENO '\$@' " INT QUIT TERM
## HUP INT QUIT ABRT KILL ALRM TERM ## 1 2 3 6 9 14 15
traps_save # Save initial traps
EOS
#cat scripts/tuirc.tpl
Simple said, the only NEW parts are msg_error and everything below until EOS.
Changing back there helps, to get rid of the 'invalid signal' messages.
However, these remains:
Code:
/usr/bin/tui-print: line 1: $'\342\210\222': command not found
I do know i've used 'somewhere' 'something like' (pseudo code): $'var'
But me cant find that anymore...
Code:
0 ~/prjs/tui $ grep "\$\'" */*
bin/tui-ftp: NUM=$$
bin/tui-log: NUM=$$
bin/tui-tar: $showBar && tui-progress -rbm $size_tarball -i $$
bin/tui-tar: $showBar && tui-progress -rbm $org_size -i $$
grep: docs/samples: Is a directory
grep: docs/tex: Is a directory
grep: locale/Anticipate-po-files: Is a directory
grep: scripts/distro: Is a directory
grep: scripts/old: Is a directory
grep: struct/bol: Is a directory
grep: struct/conf: Is a directory
grep: struct/new: Is a directory
grep: struct/str: Is a directory
grep: templates/browser.dir: Is a directory
grep: templates/manpage: Is a directory
grep: templates/scripts: Is a directory
By now i still have no idea why the invalid signals occour, or why i cant find the $' in any scripts...
Any ideas or advice from here?
Thank you in advance.
/usr/bin/tui-print: line 1: $'\342\210\222': command not found
doesn't mean that bash was trying to execute something specified using $'...', it just means that it was asked to execute a command whose name was specified as those three octal valued bytes (which do not form valid characters in the current locale), and there was no command found in $PATH matching that name. Try:
Code:
grep $'\342' ...
instead of:
Code:
grep "\$\'" ...
and if that doesn't work either, try looking for a lowercase letter b followed by a backspace. (If the last one works and you don't see why I made that wild guess, ask me after it works.)
Note that if you have something like:
Code:
$var
in your code somewhere such that it is being treated as a command name, it might be even harder to find. (Like maybe the double backslashes in the printf statement in msg_error() are causing the output from the getconf command substitutions to be executed???)
As always, bash -xv script [arg...] is your friend when trying to find out where something is going wrong.
For the record, you still have:
Code:
trap − HUP INT QUIT ABRT KILL ALRM TERM EXIT
in your script. And in the two lines in your code:
Code:
for tc in /usr/var/tmp /var/tmp /tmp $HOME/.cache;do [ -w "$tc" ] && break;done
for tl in /usr/var/log /var/log $HOME/.config/tui/logs;do [ -w "$tc" ] && break;done
I would have guessed that the tc marked in red above should be tl.
This User Gave Thanks to Don Cragun For This Post:
Was great, figured during copy paste of a trap example, i copied − and didnt change to - .
So we're back to the wrong signal.
I tried to provide the 2 most essential parts, around the loading of the generated rc file (see above), and the (still the same) errors where the actual output happens.
Code:
<...>
# Created: 2013.05.03 (rev:3)
# Changed: 2015.11.07
# Description: The loader and configuration of TUI
#
# Variables : Default
#
# Check for '$HOME'
if [ -z "$HOME" ]
then # HOME is empty, if UID is empty too, assume machine is still booting
if [ 0 -eq "${UID:-0}" ]
then # Its root, check both even though /root is not standard
known="/root /"
for k in $(awk -v FS=":" '/^root/ {print $6}' /etc/passwd 2>/dev/zero) $known
do [ -d "$k" ] && HOME="$k" && export HOME && break
done
else # Its normal user
known="/Users /home"
for k in $known # Dont quote, or it would not expand to words / paths
do [ -d "$k" ] && HOME="$k" && export HOME && break
done
fi
fi
+ '[' -z /home/sea ']'
# If its still empty, use 'cd' default behaviour to return to the users homedir if invoked without args
[ -z "$HOME" ] && HOME="${k:-$(cd;pwd)}"
+ '[' -z /home/sea ']'
# Regular definitions
TRC="${HOME:-/root}/.tuirc" # User default -- If no HOME is set, assume the computer is booting
+ TRC=/home/sea/.tuirc
TRC_SYS="$SYSCONFDIR/tuirc"
+ TRC_SYS=/tuirc
# Get paths of where it was installed
SYSCONFDIR=""
+ SYSCONFDIR=
while [ -z "$SYSCONFDIR" ]
do for install_kind in "/" "/usr" "$HOME/.local" "$HOME" "." "../conf.tui"
do tmp_cfg="$install_kind/etc/tui.conf"
[ -f "$tmp_cfg" ] && source "$tmp_cfg" #&& break
done
# [ -f "./conf.tui/" ] && source ./conf.tui/$tmp_cfg && break
done
+ '[' -z '' ']'
+ for install_kind in '"/"' '"/usr"' '"$HOME/.local"' '"$HOME"' '"."' '"../conf.tui"'
+ tmp_cfg=//etc/tui.conf
+ '[' -f //etc/tui.conf ']'
+ source //etc/tui.conf
PREFIX=/usr
++ PREFIX=/usr
BINDIR=/usr/bin
++ BINDIR=/usr/bin
SYSCONFDIR=/etc
++ SYSCONFDIR=/etc
DATADIR=/usr/share/tui
++ DATADIR=/usr/share/tui
DOCDIR=/usr/share/doc/tui
++ DOCDIR=/usr/share/doc/tui
HTMLDIR=/usr/share/doc/tui
++ HTMLDIR=/usr/share/doc/tui
INFODIR=/usr/share/info
++ INFODIR=/usr/share/info
MAN1DIR=/usr/share/man/man1
++ MAN1DIR=/usr/share/man/man1
COMPLDIR=/etc/bash_completion.d
++ COMPLDIR=/etc/bash_completion.d
HOMEBASE=//home
++ HOMEBASE=//home
+ for install_kind in '"/"' '"/usr"' '"$HOME/.local"' '"$HOME"' '"."' '"../conf.tui"'
+ tmp_cfg=/usr/etc/tui.conf
+ '[' -f /usr/etc/tui.conf ']'
+ for install_kind in '"/"' '"/usr"' '"$HOME/.local"' '"$HOME"' '"."' '"../conf.tui"'
+ tmp_cfg=/home/sea/.local/etc/tui.conf
+ '[' -f /home/sea/.local/etc/tui.conf ']'
+ for install_kind in '"/"' '"/usr"' '"$HOME/.local"' '"$HOME"' '"."' '"../conf.tui"'
+ tmp_cfg=/home/sea/etc/tui.conf
+ '[' -f /home/sea/etc/tui.conf ']'
+ for install_kind in '"/"' '"/usr"' '"$HOME/.local"' '"$HOME"' '"."' '"../conf.tui"'
+ tmp_cfg=./etc/tui.conf
+ '[' -f ./etc/tui.conf ']'
+ for install_kind in '"/"' '"/usr"' '"$HOME/.local"' '"$HOME"' '"."' '"../conf.tui"'
+ tmp_cfg=../conf.tui/etc/tui.conf
+ '[' -f ../conf.tui/etc/tui.conf ']'
+ '[' -z /etc ']'
# Get system wide default configuration paths
[ -z "$SYSCONFDIR" ] && \
printf '%s\n' "$(gettext 'Please attempt a fresh installation of TUI.')" && \
( return 1 || exit 1 )
+ '[' -z /etc ']'
source "$SYSCONFDIR/tuirc"
+ source /etc/tuirc
#!/usr/bin/env bash
# ------------------------------------------------------------------------
# Copyright (C) 1996-2015 Simon Arjuna Erat (sea) <erat.simon@gmail.com>
# All rights reserved.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
# ------------------------------------------------------------------------
#
# This file provides the core of the heart
#
# This project
TUI_VERSION=0.9.4-inprogress # 0.9.4
++ TUI_VERSION=0.9.4-inprogress
# This script
TRC_VERSION=3.0
++ TRC_VERSION=3.0
#TUI_AUTHOR="Simon Arjuna Erat (sea), Switzerland"
#
# This file is NOT meant to be changed.
#
[ -z "$TUI_DIR_CONF" ] && readonly TUI_DIR_CONF="/etc/tui"
++ '[' -z '' ']'
++ readonly TUI_DIR_CONF=/etc/tui
++ TUI_DIR_CONF=/etc/tui
[ -z "$TUI_DIR_SYSTEM" ] && readonly TUI_DIR_SYSTEM="/usr/share/tui"
++ '[' -z '' ']'
++ readonly TUI_DIR_SYSTEM=/usr/share/tui
++ TUI_DIR_SYSTEM=/usr/share/tui
#
# Paths : Used to run TUI
#
TUI_DIR_TEMP="/var/tmp"
++ TUI_DIR_TEMP=/var/tmp
TUI_DIR_LOG="/home/sea/.config/tui/logs"
++ TUI_DIR_LOG=/home/sea/.config/tui/logs
TUI_DIR_THEMES="$TUI_DIR_SYSTEM/themes"
++ TUI_DIR_THEMES=/usr/share/tui/themes
[ -z "$TUI_DIR_TEMPLATES" ] && readonly TUI_DIR_TEMPLATES="$TUI_DIR_SYSTEM/templates"
++ '[' -z '' ']'
++ readonly TUI_DIR_TEMPLATES=/usr/share/tui/templates
++ TUI_DIR_TEMPLATES=/usr/share/tui/templates
[ -z "$TUI_DIR_FUNCTIONS" ] && readonly TUI_DIR_FUNCTIONS="$TUI_DIR_SYSTEM/functions"
++ '[' -z '' ']'
++ readonly TUI_DIR_FUNCTIONS=/usr/share/tui/functions
++ TUI_DIR_FUNCTIONS=/usr/share/tui/functions
[ -z "$TUI_DIR_LOCALE" ] && readonly TUI_DIR_LOCALE="$TUI_DIR_SYSTEM/locale"
++ '[' -z '' ']'
++ readonly TUI_DIR_LOCALE=/usr/share/tui/locale
++ TUI_DIR_LOCALE=/usr/share/tui/locale
[ -z "$TUI_DIR_LIST" ] && readonly TUI_DIR_LIST="$TUI_DIR_SYSTEM/lists"
++ '[' -z '' ']'
++ readonly TUI_DIR_LIST=/usr/share/tui/lists
++ TUI_DIR_LIST=/usr/share/tui/lists
#
# Files
# Direct access to the most important configuration files for the System
#
[ -z "$TUI_FILE_CONF_APPS" ] && readonly TUI_FILE_CONF_APPS="$TUI_DIR_CONF/apps.conf"
++ '[' -z '' ']'
++ readonly TUI_FILE_CONF_APPS=/etc/tui/apps.conf
++ TUI_FILE_CONF_APPS=/etc/tui/apps.conf
[ -z "$TUI_FILE_CONF_COLORS" ] && readonly TUI_FILE_CONF_COLORS="$TUI_DIR_CONF/colors.conf"
++ '[' -z '' ']'
++ readonly TUI_FILE_CONF_COLORS=/etc/tui/colors.conf
++ TUI_FILE_CONF_COLORS=/etc/tui/colors.conf
[ -z "$TUI_FILE_CONF_COMMANDS" ] && readonly TUI_FILE_CONF_COMMANDS="$TUI_DIR_CONF/commands.conf"
++ '[' -z '' ']'
++ readonly TUI_FILE_CONF_COMMANDS=/etc/tui/commands.conf
++ TUI_FILE_CONF_COMMANDS=/etc/tui/commands.conf
[ -z "$TUI_FILE_CONF_SETTINGS" ] && readonly TUI_FILE_CONF_SETTINGS="$TUI_DIR_CONF/settings.conf"
++ '[' -z '' ']'
++ readonly TUI_FILE_CONF_SETTINGS=/etc/tui/settings.conf
++ TUI_FILE_CONF_SETTINGS=/etc/tui/settings.conf
[ -z "$TUI_FILE_CONF_SYSTEM" ] && readonly TUI_FILE_CONF_SYSTEM="$TUI_DIR_CONF/tui.conf"
++ '[' -z '' ']'
++ readonly TUI_FILE_CONF_SYSTEM=/etc/tui/tui.conf
++ TUI_FILE_CONF_SYSTEM=/etc/tui/tui.conf
[ -z "$TUI_FILE_CONF_STATUS" ] && readonly TUI_FILE_CONF_STATUS="$TUI_DIR_CONF/status.conf"
++ '[' -z '' ']'
++ readonly TUI_FILE_CONF_STATUS=/etc/tui/status.conf
++ TUI_FILE_CONF_STATUS=/etc/tui/status.conf
[ -z "$TUI_FILE_CONF_SHORTS" ] && readonly TUI_FILE_CONF_SHORTS="$TUI_DIR_CONF/shorts.conf"
++ '[' -z '' ']'
++ readonly TUI_FILE_CONF_SHORTS=/etc/tui/shorts.conf
++ TUI_FILE_CONF_SHORTS=/etc/tui/shorts.conf
[ -z "$TUI_FILE_CONF_ALIAS" ] && readonly TUI_FILE_CONF_ALIAS="$TUI_DIR_CONF/shorts-alias.conf"
++ '[' -z '' ']'
++ readonly TUI_FILE_CONF_ALIAS=/etc/tui/shorts-alias.conf
++ TUI_FILE_CONF_ALIAS=/etc/tui/shorts-alias.conf
#
# Low level workarounds, fallbacks and 'make sures' before the system config is read
#
HOMEBASE="//home" # This should provide OS independant base for regular users.
++ HOMEBASE=//home
HOME="${HOME:-$(eval echo ~${SUDO_USER:-$USER})}"
++ HOME=/home/sea
TERM="${TERM:-GNU\057Linux}"
++ TERM=xterm
WIDTH="${COLUMNS:-$(tput cols)}"
tput cols
+++ tput cols
++ WIDTH=119
HEIGHT="${LINES:-$(tput lines)}"
tput lines
+++ tput lines
++ HEIGHT=80
TUI_THEME="default"
++ TUI_THEME=default
AWK=\gawk
++ AWK=gawk
GREP=\grep
++ GREP=grep
SED=\sed
++ SED=sed
LS=\ls
++ LS=ls
#
# Color and other formatting
# Since this is also for 'endusers', this is all small letters
#
reset="\033[0m" ; invert="\033[7m"
++ reset='\033[0m'
++ invert='\033[7m'
bold="\033[1m" ; stroke="\033[9m" ; underline="\033[4m"
++ bold='\033[1m'
++ stroke='\033[9m'
++ underline='\033[4m'
# --- Colors : foreground ----- Colors : background ------------
black="\033[30m" ; bg_black="\033[40m"
++ black='\033[30m'
++ bg_black='\033[40m'
red="\033[31m" ; bg_red="\033[41m"
++ red='\033[31m'
++ bg_red='\033[41m'
green="\033[32m" ; bg_green="\033[42m"
++ green='\033[32m'
++ bg_green='\033[42m'
yellow="\033[33m" ; bg_yellow="\033[43m"
++ yellow='\033[33m'
++ bg_yellow='\033[43m'
blue="\033[34m" ; bg_blue="\033[44m"
++ blue='\033[34m'
++ bg_blue='\033[44m'
purple="\033[35m" ; bg_purple="\033[45m"
++ purple='\033[35m'
++ bg_purple='\033[45m'
cyan="\033[36m" ; bg_cyan="\033[46m"
++ cyan='\033[36m'
++ bg_cyan='\033[46m'
white="\033[37m" ; bg_white="\033[47m"
++ white='\033[37m'
++ bg_white='\033[47m'
#
# Protection and Error handling
#
break_on_injections() { # ARGS
# Searches for injection subjects
# Returns true if it finds some
#trap - HUP INT QUIT ABRT ALRM TERM EXIT
typeset arg ac=0
for arg do
ac="1"
case "" in
(*[';´|<&>']*|*':('*|*':-'*)
printf "%s\n" "Aborting, injection detected! arg${ac}='$arg'"
return 0
;;
esac
done
#trap - HUP INT QUIT ABRT ALRM TERM EXIT
return 1
}
msg_error() { # CALLER SCRIPT FUNCNAME LINENO [CONTENT]
# Prints an error message and exits
#
caller="$1" script="$2" fname="$3" lineno="$4"
shift 4
content=(${@})
printf '\r\t%s:\t%s\n' \
"Caller of script" "$caller" \
"Scriptname" "$script" \
"Functionname" "$fname" \
"Linenumber" "$lineno"
for cont in "${content[@]}";do
printf '\t%s\n' "$cont"
done
trap - HUP INT QUIT ABRT ALRM TERM EXIT
exit 1
}
#
# Traps & Error messages
#
traps_save(){ saved_traps=$(trap) ; export saved_traps ; }
traps_restore() { eval $saved_traps;}
export -f msg_error traps_save traps_restore
++ export -f msg_error traps_save traps_restore
# Set and save basic error message traping,
trap "msg_error ${CALLER:-$0} $0 ${FUNCNAME:-NON-FUNCTION} $LINENO '$@'" INT ABRT TERM
++ trap 'msg_error /usr/bin/tuirc /usr/bin/tuirc NON-FUNCTION 130 '\'''\''' INT ABRT TERM
## HUP INT QUIT ABRT KILL ALRM TERM ## 1 2 3 6 9 14 15
traps_save # Save initial traps
++ traps_save
trap
+++ trap
++ saved_traps='trap -- '\''msg_error /usr/bin/tuirc /usr/bin/tuirc NON-FUNCTION 130 '\''\'\'''\'''\''\'\'''\'''\'' SIGINT
trap -- '\''msg_error /usr/bin/tuirc /usr/bin/tuirc NON-FUNCTION 130 '\''\'\'''\'''\''\'\'''\'''\'' SIGABRT
trap -- '\'''\'' SIGUSR1
trap -- '\''msg_error /usr/bin/tuirc /usr/bin/tuirc NON-FUNCTION 130 '\''\'\'''\'''\''\'\'''\'''\'' SIGTERM'
++ export saved_traps
#
# Functions
#
<...>
VISUAL DIVIDER
Code:
<...>
+ TEXTDOMAIN=tuirc
+ TEXTDOMAINDIR=/usr/share/locale
+ export TEXTDOMAIN TEXTDOMAINDIR
date +%F
++ date +%F
+ hello_date=2015-12-26
date +%T
++ date +%T
+ hello_time=12:33:00
eval_gettext '$USER_NAME, ${hello_time} ${hello_date}'
++ eval_gettext '$USER_NAME, ${hello_time} ${hello_date}'
++ gettext '$USER_NAME, ${hello_time} ${hello_date}'
envsubst --variables "$1"
+++ envsubst --variables '$USER_NAME, ${hello_time} ${hello_date}'
++ export PATH USER_NAME hello_time hello_date
++ envsubst '$USER_NAME, ${hello_time} ${hello_date}'
+ MSG_TR_HELLO_USER='Simon Arjuna Erat (sea), 12:33:00 2015-12-26'
+ case "$1" in
+ MODE=
+ YES=false
+ case "$MODE" in
+ '[' '' = reset ']'
gettext 'hit-tab'
++ gettext hit-tab
+ HIT_TAB=hit-tab
tput cols
++ tput cols
+ COLUMNS=119
+ . /usr/share/tui/themes/default
# Simplified design:
#
# BORDER_RIGHT will be mirrored of BORDER_LEFT
# Set it manualy if it needs to be escaped.
#
BORDER_LEFT="# |"
++ BORDER_LEFT='# |'
#
# tui-header will use TUI_BACKGROUND as background color,
# and TUI_FOREGROUND as font color.
#
# tui-title will use inverted colors
#
TUI_BACKGROUND="$TUI_COLOR_BG_BLUE"
++ TUI_BACKGROUND='\033[44m'
TUI_FOREGROUND="$TUI_COLOR_FG_WHITE"
++ TUI_FOREGROUND='\033[37m'
BORDER_COLOR=""
++ BORDER_COLOR=
#
# Char indicators
#
TUI_INPUT_CHAR_READ="\076"
++ TUI_INPUT_CHAR_READ='\076'
TUI_INPUT_CHAR_SELECT="\076"
++ TUI_INPUT_CHAR_SELECT='\076'
+ n=102
+ POS='\033[102G'
eval_gettext 'TUI ($TUI_VERSION), Copyright (c) 2015 by sea'
++ eval_gettext 'TUI ($TUI_VERSION), Copyright (c) 2015 by sea'
++ gettext 'TUI ($TUI_VERSION), Copyright (c) 2015 by sea'
envsubst --variables "$1"
+++ envsubst --variables 'TUI ($TUI_VERSION), Copyright (c) 2015 by sea'
++ export PATH TUI_VERSION
++ envsubst 'TUI ($TUI_VERSION), Copyright (c) 2015 by sea'
+ tui-print -H 'TUI (0.9.4-inprogress), Copyright (c) 2015 by sea' 'Simon Arjuna Erat (sea), 12:33:00 2015-12-26'
/etc/tuirc: line 130: trap: TUI (0.9.4-inprogress), Copyright (c) 2015 by sea: invalid signal specification
/etc/tuirc: line 130: trap: Simon Arjuna Erat (sea), 12:33:00 2015-12-26': invalid signal specification
# | TUI (0.9.4-inprogress), Copyright (c) 2015 by sea Simon Arjuna Erat (sea), 12:33:00 2015-12-26 | #
<...>
Code:
# | | #
gettext 'Configure it now?'
++ gettext 'Configure it now?'
+ tui-yesno 'Configure it now?'
/etc/tuirc: line 130: trap: 0': invalid signal specification
/etc/tuirc: line 130: trap: 0': invalid signal specification
/etc/tuirc: line 130: trap: 0': invalid signal specification
/etc/tuirc: line 130: trap: 0': invalid signal specification
/etc/tuirc: line 130: trap: 0': invalid signal specification
/etc/tuirc: line 130: trap: Configure it now?': invalid signal specification
/etc/tuirc: line 130: trap: Configure it now? (y/n) : invalid signal specification | #
/etc/tuirc: line 130: trap: n': invalid signal specification
# | Configure it now? (y/n) n | #
+ exit 0
0 ~/prjs/tui $ cat -n /etc/tuirc | grep 131
131 trap "msg_error ${CALLER:-$0} $0 ${FUNCNAME:-NON-FUNCTION} $LINENO '$@'" ABRT ALRM HUP QUIT TERM 2>/dev/zero
In the end, the interesting part is - it prints the output as expected, just with a leading error output...
Something i just realized...
Code:
/etc/tuirc: line 130: trap: Configure it now?': invalid signal specification
/etc/tuirc: line 130: trap: Configure it now? (y/n) : invalid signal specification | #
/etc/tuirc: line 130: trap: n': invalid signal specification
# | Configure it now? (y/n) n | #
As the userinput was 'n', which was taken as a trap signal, i'm more confused on this subject than ever.
I removed 'INT' now, since i belive ctrl+c should not raise an error message.
Just to verify if 'everyting else' is working properly, i've redirected stderr to null "temporary".
Q (follow up): I'm afraid it'll always will be line 130, unless i define the trap somewhere else again?
As in this example: <cmd> || msg_error [args...]
---------- Post updated at 15:25 ---------- Previous update was at 13:31 ----------
I dont like it, but very often echo seems the solution...
Hi,
I tried to run snmptrapd from my customized service in centos 5.7 machine... the command used to start snmptrapd is ....
/opt/snmpdemo/bin/snmptrapd -Le -c /opt/snmpdemo/etc/snmp/snmptrapd.conf -n -C -t -m ""
And tried to trigger a trap... Trap got triggered but snmptrapd didn't... (0 Replies)
Hi all Solaris Experts,
What are the traps and pitfalls in using Solaris zones?
Specifically, what tools, utilities, system calls don't work or work differently in a non-global zone?
I'm new to zones and I've already encountered one difference which is very significant to me:
orphan... (5 Replies)
Hi,
We are using Zyrion Traverse to monitor all the servers. I like to set the traps on all of the Linux servers to send the traps to that servers.
So for on the /etc/snmp/snmp.conf file, this is what I have...
### SNMP Traps ###
trap2sink x.x.x.x # Traverse server
My... (4 Replies)
Hello everyone!
I have a text file with the next content:
2010-04-15 15:21:15 Minor 15605325 1531 Alarm name = IAD Equipment In Service location=iad01.tecnac.camino.illapel, Module=26
and I want send traps with the informationn of this file.
How I can do this?
Many... (3 Replies)
Hi all,
lately i managed to install SNMP agent on Solaris 9 & 10. The second objective is now to configure traps. However (since i'm totally new to the SUN world) i don't know a way of how to start. Can somebody help me with details? What is the first thing that you need to do to start trapping?... (3 Replies)
Hello there....unix users :)
I hope you can help me with this:
I need open a doc file or xls files and work this files whit a bash script.
For example: Open a doc file and copy information from a txt file in this doc file or xls file.
Is it possible?
Sorry for my english...I'm chilean... (3 Replies)
Good morning to you all
I´m kinda of a noob to scripting, and my knowledge is still very basic: anyway, I´ve developed a small .sh script with the following purpose:
- it will check a result file, checking if it has any values, or if it´s empty
- if it´s empty it will send an email
What... (0 Replies)
Hi all,
I have a Sun Solaris 9 box which acts as a firewall. Sometimes if multiple actions which cause snmp traps occur very close together, a single snmp trap that is sent containing the text for multiple alarms. I would like to prevent that and have a trap sent for each action which would... (0 Replies)
Well, I don't know where exactly to ask this doubt so I'm asking in the newbie section. I was reading about traps and interrupts when I thought of traps as something that cease the control of the OS from the user and interrupts that cease the control yet provide support for multitasking. Am I right... (3 Replies)
Hello
I am trying to check that SNMP traps could be sent from one server to other .
I am running this command from receiving server to see it can receive it
/usr/sbin/snoop udp port 162
and on the sending end I am running this commad
cst051 UDP D=162 S=1480 LEN=120
but i am... (1 Reply)