scriptt_mini.sh is a
minimal template for
Kornshell scripts.
scriptt_mini.sh includes
only a very small runtime for shell scripts with functionality for
logging, housekeeping, trap handling, and trouble shooting /
debugging.
scriptt_mini.sh is only a template for a shell script -- without adding your code it does not do any useful things.
Note:
A much more complex script template for shell scripts with various functions is scriptt.sh.
This description is for scriptt_mini.sh version 3.9.0.
Use the parameter -h to get a short usage help:
[xtrnaw7@t15g /data/develop/scripts]$ ./scriptt_mini.sh -h
[23.04.2022 16:49] ### scriptt_mini.sh started at 23.04.2022
16:49:33 (The PID of this process is 3039916)
Usage: <scriptname> [-h|--help]
[-v|--verbose] [-v:fn|--verbose:fn] [-q|--quiet] [-f|--force]
[-o|--overwrite] [-y|--yes] [-n|--no]
[-l|--logfile [filename[:n]|:n]
[-d{:dryrun_prefix}|--dryrun{:dryrun_prefix}]
[-D|--debugshell] [-t fn|--tracefunc fn] [-L]
[-T|--tee] [-V|--version] [--var name=value] [--appendlog]
[--nologrotate] [--noSTDOUTlog] [--print_runtime_vars]
[--nocleanup] [--nobackups] [--disable_tty_check]
Use the parameter "--help" to print the detailed help
message; use the parameter "--help -v" to also print the list
of supported environment variables
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
[23.04.2022 16:49] ### The logfile used was
/var/tmp/scriptt_mini.sh.log
[23.04.2022 16:49] ### The start time was 23.04.2022 16:49:33,
the script runtime is (day:hour:minute:seconds) 0:00:00:00 (=
0 seconds)
[23.04.2022 16:49] ### scriptt_mini.sh ended at 23.04.2022
16:49:33 (The PID of this process is 3039916; the RC is 0)
[xtrnaw7@t15g /data/develop/scripts]$
Use the parameter --help to get a detailed usage help:
Note:
These are "only" the pre-defined parameter. You can add additional parameter, of course.
Use the additional parameter -v multiple times to get
more details:
If scriptt_mini.sh is
called with the parameter -h
a short usage help is written to STDOUT; if the parameter --help is used a detailed
usage help is written to STDOUT. In both cases the parameter -v
can be used one or more times to print more details.
The function used in all cases is show_script_usage.
To avoid redundant information the function show_script_usage reads the
source of the script and prints all lines starting with some
marker in the first 3 columns of each line (without the marker):
Parameter | print lines with the Marker |
Used for |
-h | #h# | print the short usage help |
--help |
#H# and #h# |
print the short usage help and the detailed
usage help |
-h -v | #U# and #h# |
print the short usage help and the extended usage help |
--help -v |
#U#, #H# and #h# | print the short usage help, the detailed usage help, and the extended usage help |
-h -v -v | #V#, #U#, and #h# | print the short usage help, the extended usage help, and the version history |
--help -v -v |
#V#, #U#, #H#, and #h# | print the short usage help, the detailed usage help, the extended usage help and the version history |
-h -v -v -v | #T#, #V#, #U# and #h# |
print the short usage help, the extended usage help, the version history, and the template version history |
--help -v -v -v | #T#, #V#, #U#, #H#, and #h# | print the short usage help, the detailed usage help, the extended usage help, the version history and the template version history |
The function show_script_usage will print the
contents of the variable USAGE_HELP to STDOUT if
defined.
If the parameter "-v" is used at least once, the
function show_script_usage will also execute
the function show_extended_usage_help if that
function is defined.
The remaining parameter will be saved in the global variable NOT_USED_PARAMETER.
For switches that can be set via environment variable and via parameter the parameter will always overwrite the value of the environment variable.
Before processing the parameter the script stores all parameter in the global variable ALL_PARAMETER.Variablename |
Content |
Environment variable used? |
Comment |
__TEMPLATE_VERSION |
version of the script
template |
this variable is set
dynamically while running the script |
|
SCRIPT_VERSION | version of the script | this variable is set dynamically while running the script | |
__TRUE | 0 | constant for true | |
__FALSE | 1 | constant for false | |
DEFAULT_DRYRUN_PREFIX | default value for PREFIX | the value is "echo" | |
PREFIX |
prefix for executables or
commands called by the script to implement the dry-run
feature |
yes |
you must use ${PREFIX} os_command {..} for all binaries/commands in your script to use the dry-run feature Note that therefor the dry-run modes is disabled in the default (see DRYRUN_MODE_DISABLED) |
__KSH_VERSION |
ksh version - either 88 or 93 |
variable name was KSH_VERSION
in previous versions |
|
USE_ONLY_KSH88_FEATURES |
${__TRUE} if the ksh is
compatible to ksh88 only |
yes |
the default value depends on
the ksh version used to execute the script |
TYPESET_F_SUPPORTED |
"yes" if the current shell
supports "typeset -f function_name" else "no" |
some ksh88 shells (like the
one in Solaris 10) do not support this feature |
|
TRACE_FEATURE_SUPPORTED |
"yes" if the current shell
supports $0 in functions else "no" |
some ksh88 shells (like the
one in Solaris 10) do not support this feature -- see DebugShell for a workaround |
|
__SHELL |
name of the current shell executing this
script |
||
NOHUP_STDOUT_STDERR_FILE | Filename for STDOUT and STDERR if the script is switched into the background using the function switch_to_background | yes | |
ENABLE_DEBUG | if ENABLE_DEBUG is not ${__TRUE} the DebugShell and the parameter -D are disabled |
this is useful for example for scripts that can be
executed as root user via sudo |
|
__DEBUG_CODE |
debug code for the functions
-- see Tracing
function and DebugShell |
yes |
you must use eval in the debug code
and the debug code should not write to STDOUT, e.g__DEBUG_CODE="eval echo \"Current function is
\$__FUNCTION\" >&2 " ./scriptt_mini.sh |
__FUNCTIONS_WITH_DEBUG_CODE | function with debug code enabled | ||
__LIST_OF_SAVED_FUNCTIONS | list of saved functions via DebugShell alias savefunc | ||
__FUNCTION_INIT |
code to execute in every
function -- see trap handling |
||
AWK | awk binary to use | ||
ID | id binary to use | ||
EDITOR | editor binary to use with the DebugShell alias editfunc | yes | default: "which vi" |
PAGER | pager binary to use with the DebugShell alias viewsavedfunc | yes | default: "which less" and, if no less found, "which more" |
BREAK_ALLOWED |
either ${__TRUE}, ${__FALSE},
or DebugShell, Default is DebugShell |
yes |
${__TRUE} - CTRL-C aborts the
script ${__FALSE} - CTRL-C is disabled DebugShell - call the DebugShell if CTRL-C is pressed |
USAGE_HELP | additional messages that will be printed if the parameter -v and -h are used | ||
ENV_VARIABLES | list of environment variables used | ||
LIST_FUNCTIONS_AND_EXIT |
${__TRUE} if the parameter -L
is used |
||
STARTTIME_IN_SECONDS |
start time of this execution in seconds since
1.1.1970 |
||
STARTTIME_IN_HUMAN_READABLE_FORMAT |
start time of this execution in the format
dd:hh:mm:ss |
||
ENDTIME_IN_SECONDS |
end time of this execution in seconds since 1.1.1970 | this variable is set in the function die |
|
ENDTIME_IN_HUMAN_READABLE_FORMAT |
end time of this execution in the format dd:hh:mm:ss | this variable is set in the function die | |
RUNTIME_IN_SECONDS |
run time of this execution in seconds | this variable is set in the function die | |
RUNTIME_IN_HUMAN_READABLE_FORMAT |
run time of this execution in the format dd:hh:mm:ss | this variable is set in the function die | |
CUR_HOST |
hostname |
output of the command "hostname"; so either with or without domain | |
CUR_SHORT_HOST |
hostname without the domain |
||
CUR_OS |
Operating system |
output of the command "uname
-s" |
|
CUR_OS_VERSION |
OS version |
output of the command "uname -r" | |
CUR_SHELL | current shell used | ||
SYSTEMD_IS_USED |
${__TRUE} if systemd is used on this machine
else ${__FALSE} |
||
SCRIPTNAME |
name of the script as used by
the user (e.g. ./myscript.sh, /home/user/myscript.sh) |
||
SCRIPTDIR |
directory with the script as
used by the user ( e.g. ./ , ../bin/,
/usr/local/bin) |
||
REAL_SCRIPTDIR |
absolute path for the script
(always starting with a /) |
||
REAL_SCRIPTNAME |
fully qualified name of the
script |
||
WORKING_DIR |
current working directory at
script start |
||
LOGFILE |
log file for the script,
default is /var/tmp/<scriptname>.log |
yes |
use the parameter -l to
change the logfile used; use the parameter -l none to not use a
logfile |
LOGFILE_FOUND LOG_MESSAGE_CACHE |
internal variables for the
log file handling -- do not change |
The functions to write log
messages will store the messages in the variable LOG_MESSAGE_CACHE
until the name of the log file to use is fix. |
|
__TEE_OUTPUT_FILE | file for the output of STDOUT
and STDERR if the parameter -T is used |
yes |
default value is /var/tmp/${0##*/}.$$.tee.log
|
__PPID |
internal variable used by the
code to implement the parameter -T/--tee |
see the source code for
details |
|
__MAINRC |
internal variable used by the code to implement the parameter -T/--tee | see the source code for details | |
ALL_PARAMETER | all parameter for the script |
||
NOT_USED_PARAMETER | the script parameter that are
not processed by the runtime code |
||
DRYRUN_MODE_DISABLED |
if set to ${__TRUE} : disable
the dry run mode (-> the parameter "-d" will be
ignored); set this variable to ${__FALSE} to enable
activating the dry run mode via parameter "-d" |
the dry run feature is
disabled in the default settings because it only works if
all external commands are prefixed with ${__PREFIX} |
|
CUR_USER_ID |
UID (e.g. 1000) |
||
CUR_USER_NAME |
user name (e.g. max) |
||
CUR_GROUP_ID |
GID (e.g. 1000) |
||
CUR_GROUP_NAME |
group name (e.g. staff) |
||
RUNNING_IN_TERMINAL_SESSION |
${__TRUE} - the script is
running in an interactive session; ${__FALSE} - the script
is running in a session without a tty |
if the parameter --disable_tty_check
is used this variable is always ${__TRUE} |
|
DISABLE_TTY_CHECK |
${__TRUE} - disable the check
for a tty and always assume we do have a tty |
yes |
|
DIRS_TO_REMOVE |
directories that should be deleted at script end in the cleanup function | ||
FILES_TO_REMOVE |
files that should be deleted at script end in the cleanup function | ||
PROCS_TO_KILL |
processes that should be killed at script end in the cleanup function | ||
KILL_PROC_TIMEOUT |
number of seconds to wait
after the "kill <pid>" command in the housekeeping
routine until a "kill -9 <pid>" is issued Use "-1" to disable "kill -9 <pid>". |
this is only the default
timeout value for all PIDs; you can define a different
timeout for each PID in PROCS_TO_KILL using the syntax PID:timeout_in_seconds. |
|
CLEANUP_FUNCTIONS |
commands to execute in the cleanup
function before doing the other cleanup tasks
(e.g.kill processes, remove temporary files and directories,
etc) |
||
FINISH_FUNCTIONS |
commands to execute in the finish function after doing the other cleanup tasks (e.g.kill processes, remove temporary files and directories, etc) | ||
MOUNTS_TO_UMOUNT | temporary mount points to umount in the function cleanup function | ||
APPLICATION_VARIABLES |
additional variables to print
in the DebugShell |
||
RUNTIME_VARIABLES |
variables to print in the
DebugShell, see DebugShell |
||
QUIET |
${__TRUE} if the parameter -q
is used |
yes |
|
FORCE |
${__TRUE} if the parameter -f
is used |
yes |
|
VERBOSE |
${__TRUE} if the parameter -v
is used |
yes |
|
VERBOSE_LEVEL |
if this variable is greater
then 1 the script also prints the runtime messages; use
multiple times "-v" to increase the
VERBOSE_LEVEL |
yes |
|
APPEND_LOG | ${__TRUE} if the parameter --appendlog is used | def. : overwrite an existing logfile | |
LOG_STDOUT | ${__FALSE} if the parameter --noSTDOUTlog is used | if ${__FALSE}: do not write STDOUT/STDERR to a file if STDIN is not a tty | |
ROTATE_LOG |
${__FALSE} if the parameter --nologrotate
is used or if the logfile is already rotated |
||
NO_OF_LOGFILES_TO_KEEP |
number of logfiles to keep while doing the
log rotate |
yes |
|
PRINT_COMMAND_TO_EXECUTE |
the function executeCommandAndLog
will print the command to execute if this variable is
${__TRUE} |
||
__USER_RESPONSE_IS |
"y" if parameter -y is used; "n" if
parameter -n is
used; else empty |
if the variable
__USER_RESPONSE_IS is either "y" or "n" the function AskUser
will use that value and not request input from the user |
|
__NOECHO |
variable for the function AskUser: Do not print the user input if set to ${__TRUE} | default is ${__FALSE} |
|
__USE_TTY |
variable for the function AskUser: User /dev/tty instead of STDIN or STDOUT if set to ${__TRUE} | default is ${__FALSE} | |
__DEBUG_SHELL_IN_ASKUSER |
variable for the function AskUser: Allow to call the DebugShell in AskUser if set to ${__TRUE} | default is ${__TRUE} | |
__STTY_SETTINGS |
stty settings; used in the
function die to reset the stty settings if
neccessary |
||
USER_INPUT LAST_USER_INPUT |
global variables for the user input used in the function
AskUser |
||
INSIDE_DIE |
${__TRUE} if inside of the
function die |
||
INSIDE_DEBUG_SHELL |
${__TRUE} if inside of the
function DebugShell |
||
INSIDE_CLEANUP_ROUTINE |
${__TRUE} if inside of one of
the cleanup routines |
||
INSIDE_FINISH_ROUTINE | ${__TRUE} if inside of one of
the finish routes |
||
INSIDE_USR1_HANDLER |
${__TRUE} if inside the trap
handler for the signal USR1 |
||
INSIDE_USR2_HANDLER | ${__TRUE} if inside the trap handler for the signal USR2 | ||
INSIDE_BREAK_HANDLER |
${__TRUE} if inside the trap
handler for the signal BREAK |
||
INSIDE_HUP_HANDLER | ${__TRUE} if inside the trap
handler for the signal HUP |
||
INSIDE_EXIT_HANDLER | ${__TRUE} if inside the trap
handler for the signal EXIT |
||
INSIDE_QUIT_HANDLER | ${__TRUE} if inside the trap
handler for the signal QUIT |
||
DEBUG_SHELL_CALLED |
${__TRUE} if the debug shell was executed at
least one time |
the runtime system will never reset this
variable to ${__FALSE} again |
|
NO_CLEANUP | do not any house keeping at script end if set to ${__TRUE} | ||
NO_EXIT_ROUTINES | do not execute the exit routines if set to ${__TRUE} |
||
NO_TEMPFILES_DELETE | do not delete temporary files if set to ${__TRUE} | ||
NO_TEMPDIR_DELETE | do not delete temporary directories if set to ${__TRUE} | ||
NO_FINISH_ROUTINES | do not execute the finish routines if set to ${__TRUE} | ||
NO_KILL_PROCS | do not kill the processes if set to ${__TRUE} | ||
NO_UMOUNT_MOUNTPOINTS |
do not umount temporary mount points if set to ${__TRUE} | ||
RUNNING_ON_A_VIRTUAL_MACHINE |
${__TRUE} if the script is running in a
virtual machine |
||
THIS_IS_A_VMWARE_MACHINE |
${__TRUE} if the script is running in a VMWare virtual machine | ||
SYSTEM_PRODUCT_NAME |
content of /sys/class/dmi/id/product_name |
||
SYSTEM_PRODUCT_VENDOR |
content of /sys/class/dmi/id/sys_vendor |
||
HPYERVISOR_VENDOR |
VMware, VirtualBox, qemu, or an empty string
if running on a physical machine |
||
RCM_SERVICE RCM_FUNCTION RCM_HOSTID_FILE RCM_HOSTID RCM_DBQUERY RCM_DBGET_FILE RCM_USERID RCM_PASSWORD FOUND_APPL_PARAM_ENTRY_KEYS RCM_APPL_PARAMS_KEY RCM_APPL_PARAMS_VAL |
variables used for an RCM environment - - just ignore or delete them if not used | ||
The default log file is /var/tmp/${SCRIPTNAME}.log. If the script can not write to that log file it uses the log file /var/tmp/${SCRIPTNAME}.log.$$.
Use the parameter --appendlog to extend an existing logfile; in the default the script will always create a new log file.
Function |
Purpose |
Comment |
LogMsg |
write a message to STDOUT and
also to the logfile |
|
LogOnly |
write a message only to the
logfile |
LogMsg is used to write the
message |
LogInfo |
write the message prefixed with "INFO: " to STDERR and the logfile if VERBOSE is ${__TRUE} | LogMsg is used to write the message |
LogError |
write the message prefixed
with "ERROR: " to STDERR and the logfile |
LogMsg is used to write the message |
LogWarning |
write the message prefixed
with "WARNING: " to STDOUT and the logfile |
LogMsg is used to write the message |
LogMoreInfo |
write a message prefixed with "INFO:" to
STDERR and the logfile if the variable VERBOSE is ${__TRUE}
and if the variable QUIET is not ${__TRUE} |
|
LogRuntimeInfo |
internal function to print
the verbose messages of the runtime system to STDERR and the
logfile |
LogMsg is used to write the message |
RotateLog |
Rotate a file; used for the
log rotate |
You can use this function to
rotate any file, the usage is RotateLog [file1 [... [file#]]] The function will keep NO_OF_LOGFILES_TO_KEEP old log files. |
scriptt_mini.sh supports a simple dry-run feature: In
dry-run mode every command is prefixed with ${PREFIX};
the default value for the variable PREFIX
is "echo ".
To use the dry-run feature of the script for your commands also
use always
${PREFIX} os_command {...}
for all commands used in your script that might change something. "${PREFIX}" is empty in non-dryrun mode; in dry-run mode it is set to "echo " (or what ever you define with the parameter -d).
Note:
In the default settings activating the dry run mode via parameter
is disabled beacuse the variable DRYRUN_MODE_DISABLED is
set to ${__TRUE}; to enable activating the dry run mode set the
variable DRYRUN_MODE_DISABLED to ${__FALSE} in the script.
To execute a command and write all output of the command to
STDOUT/STDERR also to the logfile use
executeCommandAndLog ${PREFIX}
os_command {...}
The returncode of executeCommandAndLog is the returncode of the
command executed.
For simple and fast commands you can also use code like this
CUR_OUTPUT="$( <your_command>
2>&1 )"
TEMPRC=$?
LogMsg "-" "${CUR_OUTPUT}"
if [ ${TEMPRC} = 0 ] then
echo "command was sucessfull"
else
echo "command was not sucessfull"
fi
There is also a function to execute a command (either an external executable or an internal function) with a timeout: runcmd_with_timeout :
#
----------------------------------------------------------------------
# runcmd_with_timeout
#
# function: run a function or command with timeout
#
# usage: runcmd_with_timeout [timeout_value]
[kill_signal] [cmd] [parameter]
#
# returns:
#
# the return code of the function is
the return code of the program executed but only if the
program finished before hitting the timeout.
# If the program is killed by the
timeout function the return code of the function is 249.
# If the first parameter of the
function is invalid the function ends with the return code 248
#
# parameter:
#
# timeout_value
# timeout value in seconds,
use #m for minutes, #h for hours, or (optional) #s for seconds
#
# kill_signal
# use "kill
-${kill_signal}" to kill the program when the timeout is
reached ("kill -9" is neccessary for example for some shell
scripts)
# default is kill with the
standard signal to kill a process (which is 15)
# kill_signal must be a
number
#
# cmd
# command to execute; the
command can NOT be a number
# "cmd" can be an external
command or a function in the script
#
# parameter
# parameter for the command
to execute
#
# Be carefull with writing messages to
STDOUT/STDERR or into the logfile of this script.
#
# Note:
#
# The function does NOT work in AIX
#
# Credits for this function
# https://stackoverflow.com/questions/24412721/elegant-solution-to-implement-timeout-for-bash-commands-and-functions
scriptt_mini.sh installs a trap
handler for CTRL-C . To disable CTRL-C set the variable BREAK_ALLOWED to ${__FALSE};
to enable CTRL-C set the variable BREAK_ALLOWED to ${__TRUE}; to call the DebugShell if CTRL-C is pressed set the
variable BREAK_ALLOWED to
DebugShell.
Default value for BREAK_ALLOWED
is "DebugShell".
To do the house keeping at script end you should always use the
function die to end the
script.
The usage for the function die
is
die [script_return_code] [message_to_print]
The default for the parameter script_return_code is 0;
there is no default for the parameter message_to_print.
The function die uses
the function cleanup to
do the house keeping. cleanup
does these tasks in this order:
scriptt_mini.sh installs
a trap handler for the signal EXIT to
do the house keeping at script end even if the function die was not used to end the
script.
To configure the house keeping for your script do:
To execute a function at script end before the other housekeeping steps are done use
CLEANUP_FUNCTIONS="${CLEANUP_FUNCTIONS}
<your_cleanup_function>"
CLEANUP_FUNCTIONS="${CLEANUP_FUNCTIONS}
myfunction:myparameter1:myparameter2:myparameter3"
To start a process in the background that should be killed at
script end if it's still running use
<start_process> &
ps -p $! >/dev/null &&
PROCS_TO_KILL="${PROCS_TO_KILL} $!"
The cleanup function waits up to KILL_PROC_TIMEOUT seconds after the kill command to check if kill was sucessfull. If the kill command was not sucessfull the script uses "kill -9" to kill the process.
To change the timeout value for a process use
PROCS_TO_KILL="${PROCS_TO_KILL}
<process_to_kill:timeout_for_this_process>"
To disable the "kill -9" for a process use
PROCS_TO_KILL="${PROCS_TO_KILL}
<process_to_kill:-1>"
To create a file that should be removed at script end if it
still exists use
touch "${NEW_FILE}" &&
FILES_TO_REMOVE="${FILES_TO_REMOVE} ${NEW_FILE}
"
To umount a temporary mount point at script end if it's still mounted use
TEMP_MOUNTPOINT="<temporary_mount_point>"
NFS_SHARE="<nfs
share>"
mkdir -p
"${TEMP_MOUNTPOINT}" &&
DIRS_TO_REMOVE="${DIRS_TO_REMOVE}
${TEMP_MOUNTPOINT}
" && \
mount "${NFS_SHARE}" "${TEMP_MOUNTPOINT}"
&& MOUNTS_TO_UMOUNT="${MOUNTS_TO_UMOUNT}
${TEMP_MOUNTPOINT}"
To create a directory that should be removed at script end if it
still exists use
mkdir -p "${NEW_DIR}" &&
DIRS_TO_REMOVE="${DIRS_TO_REMOVE} ${NEW_DIR}
"
To execute a function at script end after the other housekeeping steps are done use
FINISH_FUNCTIONS="${FINISH_FUNCTIONS}
<your_finish_function>"
FINISH_FUNCTIONS="${FINISH_FUNCTIONS}
myfunction:myparameter1:myparameter2:myparameter3"
To disable the house keeping at script end use the parameter --nocleanup;
to only disable one or more house keeping steps set the approbiate
variable from the list below to true (= 0 ) either in the script
or using the parameter "--var varname=0".
Signal |
Trap
Handler |
Comment |
EXIT |
signal_exit_handler |
house keeping cleanup |
BREAK | signal_break_handler |
disable or enable CTRL-C |
USR1 | signal_usr1_handler |
call the DebugShell |
USR2 |
signal_usr2_handler | the handler does nothing in
the default config |
HUP |
signal_hup_handler | the handler does nothing in the default config |
QUIT |
signal_quit_handler |
house keeping cleanup |
# alias to install the trap handler
#
# Note: The statement LINENO=${LINENO} is necessary to use the
variable LINENO in the trap command
# USR1 and USR2 are
different values in the various Unix OS!
#
# Number KSH name Comments
# 0
EXIT This number does not
correspond to a real signal, but the corresponding trap is
executed before script termination.
# 1
HUP hangup
# 2
INT The interrupt
signal typically is generated using the DEL or the ^C key
# 3
QUIT The quit signal is
typically generated using the ^[ key. It is used like the INT
signal but explicitly requests a core dump.
# 9
KILL cannot be caught or
ignored
# 10 BUS
bus error
# 11 SEGV
segmentation violation
# 13 PIPE
generated if there is a pipeline without
reader to terminate the writing process(es)
# 15 TERM
generated to terminate the process gracefully
# 16 USR1
user defined signal 1, this value is
different in other Unix OS!
# 17 USR2
user defined signal 2, this value is
different in other Unix OS!
# -
DEBUG KSH only: This is no
signal, but the corresponding trap code is executed before each
statement of the script.
#
alias __settraps="
LINENO=\${LINENO} ;\
trap 'signal_hup_handler \${LINENO}' 1
;\
trap 'signal_break_handler \${LINENO}' 2 ;\
trap 'signal_quit_handler \${LINENO}' 3 ;\
trap 'signal_exit_handler \${LINENO}' 15 ;\
trap 'signal_usr1_handler \${LINENO}' USR1 ;\
trap 'signal_usr2_handler \${LINENO}'
USR2 ;\
"
# alias to reset all traps to the defaults
#
alias __unsettraps="
LINENO=\${LINENO} ;\
trap - 1 ;\
trap - 2 ;\
trap - 3 ;\
trap - 15 ;\
trap - USR1 ;\
trap - USR2 ;\
"
__FUNCTION_INIT="eval __settraps"
To start a script based on scriptt_mini.sh as daemon just
use nohup and/or a traling &, e.g.
nohup /your_scriptt.sh &
Another method to use the script as daemon is the function switch_to_background:
The function switch_to_background will redirect
STDOUT and STDERR to a file and switch the current process running
the script into the background.
SEMFILE="/tmp/stop"
echo "The PID of this process is $$"
ps -ef | grep $$
switch_to_background
LogMsg "Now running in the background ..."
while [ ! -r ${SEMFILE} ] ; do
echo "$( date ) : ${SCRIPTNAME}; PID $$ is still running
; the semaphor file to stop the script is ${SEMFILE} "
echo " This messages goes to STDERR" >&2
sleep 1
done
Sample output :
[root@t540p /data/develop/scripts]$ ./scriptt_mini.sh
[16.08.2018 15:57 ] ### scriptt_mini.sh started at Thu Aug 16
15:57:01 CEST 2018
[16.08.2018 15:57 ] ### The logfile used is
/var/tmp/scriptt_mini.sh.log
[16.08.2018 15:57 ] Hello World, you must add your own code here
to do something useful
The PID of this process is 23907
root 23907 4173 0 15:57
pts/7 00:00:00 /bin/ksh ./scriptt_mini.sh
root 23948 23907 0 15:57
pts/7 00:00:00 ps -ef
root 23949 23907 0 15:57
pts/7 00:00:00 grep 23907
[16.08.2018 15:57 ] Switching the process for the script
"scriptt_mini.sh" with the PID 23907 into the background now ...
[16.08.2018 15:57 ] STDOUT/STDERR now goes to the file
"/data/develop/scripts/nohup.out"
[1]+
Stopped
./scriptt_mini.sh
[root@t540p /data/develop/scripts]$
[16.08.2018 15:57 ] *** The script "scriptt_mini.sh" (PID is
23907) should now run in the background ...
[root@t540p /data/develop/scripts]$ tail -f
/data/develop/scripts/nohup.out
Thu Aug 16 15:57:08 CEST 2018 : scriptt_mini.sh; PID 23907 is
still running ; the semaphor file to stop the script is
/tmp/stop
This messages goes to STDERR
Thu Aug 16 15:57:09 CEST 2018 : scriptt_mini.sh; PID 23907 is
still running ; the semaphor file to stop the script is
/tmp/stop
This messages goes to STDERR
Thu Aug 16 15:57:10 CEST 2018 : scriptt_mini.sh; PID 23907 is
still running ; the semaphor file to stop the script is
/tmp/stop
This messages goes to STDERR
Thu Aug 16 15:57:11 CEST 2018 : scriptt_mini.sh; PID 23907 is
still running ; the semaphor file to stop the script is
/tmp/stop
This messages goes to STDERR
Thu Aug 16 15:57:12 CEST 2018 : scriptt_mini.sh; PID 23907 is
still running ; the semaphor file to stop the script is
/tmp/stop
This messages goes to STDERR
Thu Aug 16 15:57:13 CEST 2018 : scriptt_mini.sh; PID 23907 is
still running ; the semaphor file to stop the script is
/tmp/stop
This messages goes to STDERR
Thu Aug 16 15:57:14 CEST 2018 : scriptt_mini.sh; PID 23907 is
still running ; the semaphor file to stop the script is
/tmp/stop
This messages goes to STDERR
Thu Aug 16 15:57:15 CEST 2018 : scriptt_mini.sh; PID 23907 is
still running ; the semaphor file to stop the script is
/tmp/stop
This messages goes to STDERR
^C
[root@t540p /data/develop/scripts]$
The function switch_to_background does the same as a key combination CTRL-Z with a "bg" afterwards. Therefor you can switch the process back into the foreground with the command "fg" but only in the session in which the script was executed. Be aware that switching the process into the foreground again will not change the output of STDOUT and STDERR back to the tty of the session.
Use the environment variable NOHUP_STDOUT_STDERR_FILE to change the name of the file used for STDOUT and STDERR in the background process.
Note: The function switch_to_background
will not redirect STDOUT if called with the parameter no_redirect;
the function does not redirect or close STDIN.
The function switch_to_background was tested in RHEL, Solaris 10, AIX, and MacOS (Darwin).
The parameter --var can be used to change the
value of a variable, e.g.:
To simulate the parameter -v -v you can use
[xtrnaw7@t540p /data/develop/scripts]$ ./scriptt_mini.sh
--var VERBOSE=0 --var VERBOSE_LEVEL=2
[10.12.2017 13:12 ] ### scriptt_mini.sh started at Sun Dec 10
13:12:22 CET 2017
[10.12.2017 13:12 ] Found --VAR parameter for VERBOSE="0"
[10.12.2017 13:12 ] Current value of VERBOSE is: "1"
[10.12.2017 13:12 ] New value of VERBOSE is now: "0"
[10.12.2017 13:12 ] Found --VAR parameter for VERBOSE_LEVEL="2"
[10.12.2017 13:12 ] Current value of VERBOSE_LEVEL is: "0"
[10.12.2017 13:12 ] New value of VERBOSE_LEVEL is now: "2"
[10.12.2017 13:12 ] ### The logfile used is
/var/tmp/scriptt_mini.sh.log
[10.12.2017 13:12 ] Hello World, you must add your own code here
to do something useful
[10.12.2017 13:12 ] INFO: Housekeeping process started ....
[10.12.2017 13:12 ] INFO: No cleanup functions defined.
[10.12.2017 13:12 ] INFO: No processes to kill defined.
[10.12.2017 13:12 ] INFO: No files to delete defined
[10.12.2017 13:12 ] INFO: No directories to remove defined.
[10.12.2017 13:12 ] INFO: No finish functions to executed
defined.
[10.12.2017 13:12 ] ### The logfile used was
/var/tmp/scriptt_mini.sh.log
[10.12.2017 13:12 ] ### scriptt_mini.sh ended at Sun Dec 10
13:12:22 CET 2017
[xtrnaw7@t540p /data/develop/scripts]$
To disable deleting files and killing of still running processes
at the end of the script use:
[root@t540p /data/develop/scripts]# ./scriptt_mini.sh
-v -v --var NO_KILL_PROCS=0 --var:NO_TEMPFILES_DELETE=0
[12.08.2018 12:02 ] ### scriptt_mini.sh started at Sun Aug 12
12:02:30 CEST 2018
[12.08.2018 12:02 ] Found --VAR parameter for NO_KILL_PROCS="0"
[12.08.2018 12:02 ] Current value of NO_KILL_PROCS is: ""
[12.08.2018 12:02 ] New value of NO_KILL_PROCS is now: "0"
[12.08.2018 12:02 ] Found --VAR parameter for
NO_TEMPFILES_DELETE="0"
[12.08.2018 12:02 ] Current value of NO_TEMPFILES_DELETE is: ""
[12.08.2018 12:02 ] New value of NO_TEMPFILES_DELETE is now: "0"
[12.08.2018 12:02 ] ### The logfile used is
/var/tmp/scriptt_mini.sh.log
[12.08.2018 12:02 ] Hello World, you must add your own code here
to do something useful
[12.08.2018 12:02 ] INFO: This is an info message
[12.08.2018 12:02 ] INFO: Housekeeping process started ....
[12.08.2018 12:02 ] INFO: No cleanup functions defined or
cleanup functions disabled
[12.08.2018 12:02 ] INFO: No processes to kill defined or
process killing disabled
[12.08.2018 12:02 ] INFO: No files to delete defined or files
deleting disabled
[12.08.2018 12:02 ] INFO: No directories to remove defined or
directory removing disabled
[12.08.2018 12:02 ] INFO: Umounting the mount points to umount
"" ...
[12.08.2018 12:02 ] INFO: No finish functions defined or finish
functions disabled
[12.08.2018 12:02 ] ### The logfile used was
/var/tmp/scriptt_mini.sh.log
[12.08.2018 12:02 ] ### scriptt_mini.sh ended at Sun Aug 12
12:02:30 CEST 2018
[root@t540p /data/develop/scripts]#
To trace one or more functions the parameter "-t fn" can be used. Tracing is
implemented with the variable __DEBUG_CODE. So
for this feature the function should be defined like this
...
}
The code in __DEBUG_CODE. checks $0
and the local variable __FUNCTION for the name
of the function . Unfortunately $0 in functions
is not supported by all ksh implementations. Therefor you should
start each function like this:
function <your_function_name> {
typeset __FUNCTION="<function_name>"
${__DEBUG_CODE}
${__FUNCTION_INIT...
If running in a ksh93 compatible shell the variable $.sh.func is also supported by the debug code and the variable __FUNCTION is optional.
The code in __DEBUG_CODE looks like this
for ksh88 compatible shells:
eval [ 0 = 1 -o "$0"x = "MyFunction"x -o
"${__FUNCTION}"x = "MyFunction"x -o "$0"x =
"MyFunction1"x -o "${__FUNCTION}"x = "MyFunction1"x ]
&& printf "
*** Enabling trace for the function ${__FUNCTION:=$0} ...
" >&2 && set -x
and for ksh93 compatible shells:
eval __FUNCTION="${.sh.fun}" ; [ 0 = 1 -o "$0"x
= "MyFunction"x -o "${__FUNCTION}"x = "MyFunction"x -o
"$0"x = "MyFunction1"x -o "${__FUNCTION}"x =
"MyFunction1"x ] && printf "
*** Enabling trace for the function ${__FUNCTION:=$0} ...
" >&2 && set -x
If a function that should be traced does not start with "${__DEBUG_CODE}" and the shell used supports dynamic changing the code for a function the script will temporary add the statements
typeset __FUNCTION=<function_name>; ${__DEBUG_CODE}to the function and document this with the log message
Adding debug code to the function
"<function_name>"
Changing a function dynamically works with some ksh versions but
not all. The script will print the status "change
function code supported: no
" in the
usage help and in the DebugShell if
this feature is not supported by the current shell. Some ksh
versions do not support the usage of $0 in functions. The script prints the status of
this feature also if called with the parameter -h and in the DebugShell.
e.g.
[xtrnaw7@t540p /data/develop/scripts]$
./scriptt_mini.sh -h | grep environment
Current environment: ksh version: 93 | change
function code supported: no | tracing feature using $0
supported: no
[xtrnaw7@t540p /data/develop/scripts]$
and in the DebugShell
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change
function code supported: no | tracing feature using $0
supported: no
>>
[xtrnaw7@t540p /data/develop/scripts]$
./scriptt_mini.sh -v
-t
MyFunction,Myfunction1,MyFunction1 -t die
[04.11.2017 17:44 ] ### scriptt_mini.sh started at Sat
Nov 4 17:44:29 CET 2017
[04.11.2017 17:44 ] ### The logfile used is
/var/tmp/scriptt_mini.sh.log
[04.11.2017 17:44 ] Enabling
trace for the function "MyFunction" ...
[04.11.2017 17:44 ] Enabling
trace for the function "Myfunction1" ...
[04.11.2017 17:44 ] The
function "Myfunction1" is not defined
[04.11.2017 17:44 ] Enabling
trace for the function "MyFunction1" ...
[04.11.2017 17:44 ] Adding
debug code to the function "MyFunction1" ...
[04.11.2017 17:44 ] Enabling
trace for the function "die" ...
[04.11.2017 17:44 ] Hello World, you must add your own code
here to do something useful
*** Enabling trace for the
function MyFunction ...
+ THISRC=0
+ typeset THISRC
+ NO_OF_LINES=0
+ typeset NO_OF_LINES
+ LINENO=1410
+ typeset LINENO
+ CUR_VAR=''
+ typeset CUR_VAR
+ LogMsg 'This is a test function'
[04.11.2017 17:44 ] This is a test function
+ date
$'+DATE=%Y-%m-%d\n
YEAR=%Y\n
MONTH=%m\n
DAY=%d\n
TIME=%H:%M:%S\n
HOUR=%H\n
MINUTE=%M\n
SECOND=%S\n
datestamp=%Y-%m-%d_%H.%M.%S\n
DayOfWeek=%a\n
MonthAbbrev=%b'
+ eval
DATE=$'2017-11-04\n
YEAR=2017\n
MONTH=11\n
DAY=04\n
TIME=17:44:29\n
HOUR=17\n
MINUTE=44\n
SECOND=29\n
datestamp=2017-11-04_17.44.29\n
DayOfWeek=Sat\n
MonthAbbrev=Nov'
+ DATE=2017-11-04
+ YEAR=2017
+ MONTH=11
+ DAY=04
+ TIME=17:44:29
+ HOUR=17
+ MINUTE=44
+ SECOND=29
+ datestamp=2017-11-04_17.44.29
+ DayOfWeek=Sat
+ MonthAbbrev=Nov
+ eval echo 'YEAR is $YEAR'
+ echo YEAR is 2017
YEAR is 2017
+ eval echo 'MONTH is $MONTH'
+ echo MONTH is 11
MONTH is 11
+ eval echo 'DAY is $DAY'
+ echo DAY is 04
DAY is 04
+ eval echo 'TIME is $TIME'
+ echo TIME is 17:44:29
TIME is 17:44:29
+ eval echo 'HOUR is $HOUR'
+ echo HOUR is 17
HOUR is 17
+ eval echo 'MINUTE is $MINUTE'
+ echo MINUTE is 44
MINUTE is 44
+ eval echo 'SECOND is $SECOND'333
+ echo SECOND is 29
SECOND is 29
+ eval echo 'datestamp is $datestamp'
+ echo datestamp is 2017-11-04_17.44.29
datestamp is 2017-11-04_17.44.29
+ eval echo 'DayOfWeek is $DayOfWeek'
+ echo DayOfWeek is Sat
DayOfWeek is Sat
+ eval echo 'MonthAbbrev is $MonthAbbrev'
+ echo MonthAbbrev is Nov
MonthAbbrev is Nov
+ [ -r /data/develop/scripts/scriptt_mini.sh ]
+ wc -l /data/develop/scripts/scriptt_mini.sh
+ NO_OF_LINES='1686 /data/develop/scripts/scriptt_mini.sh'
+ LogMsg '/data/develop/scripts/scriptt_mini.sh has 1686
/data/develop/scripts/scriptt_mini.sh lines'
[04.11.2017 17:44 ] /data/develop/scripts/scriptt_mini.sh has
1686 /data/develop/scripts/scriptt_mini.sh lines
+ THISRC=0
+ return 0
*** Enabling trace for the
function MyFunction1 ...
+ THISRC=0
+ typeset THISRC
+ LogMsg 'Inside of MyFunction1'
[04.11.2017 17:44 ] Inside of MyFunction1
+ return 0
*** Enabling trace for the
function die ...
+ THISRC=0
+ typeset THISRC
+ [ 0x '=' x ]
+ INSIDE_DIE=0
+ trap '' EXIT
+ trap '' SIGUSR1
+ trap '' SIGUSR2
+ trap '' SIGINT
+ trap '' SIGHUP
+ [ x '!=' x ]
+ cleanup
+ [ 1 -ne 0 ]
+ shift
+ [ 0 -ne 0 ]
+ [ /var/tmp/scriptt_mini.sh.logx '!=' x -a -f
/var/tmp/scriptt_mini.sh.log ]
+ LogMsg '### The logfile used was
/var/tmp/scriptt_mini.sh.log'
[04.11.2017 17:44 ] ### The logfile used was
/var/tmp/scriptt_mini.sh.log
+ date
+ LogMsg '### scriptt_mini.sh ended at Sat Nov 4
17:44:29 CET 2017'
[04.11.2017 17:44 ] ### scriptt_mini.sh ended at Sat Nov
4 17:44:29 CET 2017
+ exit 0
[xtrnaw7@t540p /data/develop/scripts]$
The DebugShell is in
principle only a loop that reads a line from the user and executes
it. DebugShell reads and writes
to /dev/tty so you can also use it with STDOUT
redirection of your script.
DebugShell is disabled
if STDIN is not a tty. To call a DebugShell before starting the
script use the parameter -D;
to view the online help for the DebugShell menu use "help":
The aliase defined in the DebugShell are:
[xtrnaw7@t540p /data/develop/scripts]$ ./scriptt_mini.sh
-D
[03.03.2018 09:20 ] ### scriptt_mini.sh started at Sat
Mar 3 09:20:09 CET 2018
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> help
vars
- print the runtime variable values
functions |
funcs - list
all defined functions
functions fn | funcs fn - list functions matching
the regex fn
func
fn
- view the source code for the function fn (supported by this
shell: yes)
savedfuncs
- list the saved functions (supported by this shell: yes)
editfunc
fn
- edit the source code for the function fn (supported by this
shell: yes)
savefunc
fn
- save the source code of the function fn (supported by this
shell: yes)
viewsavedfunc
fn -
view the source code of the saved function fn (supported by
this shell: yes)
restorefunc
fn
- restore the source code of the function fn (supported by
this shell: yes)
clearsavedfunc
fn - delete
the saved source code of the function fn (supported by this
shell: yes)
verbose
- toggle the verbose switch (Current value: 0)
view_debug
- view the current trace settings
clear_debug
- clear the tracing for all functions
set_debug
fn
- enable tracing for the functions fn; use "+fn" to preserve
existing settings
add_debug_code
fn - enable
debug code for the functions fn (supported by this shell: yes)
exit
- exit the debug shell
quit
- end the script using die
abort
- abort the script using kill -9
!<code>
- execute the instructions "<code>"
<code>
- execute the instructions using "eval <code>"
Notes:
"fn" can be one or more function names or regex; use
"functions fn" to test the value of "fn"
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
The alias vars lists all
runtime variables with values:
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> vars
*** constants
__TRUE: "0"
__FALSE: "1"
*** signal handling:
BREAK_ALLOWED: "DebugShell"
INSIDE_DIE: "1"
INSIDE_DEBUG_SHELL: "0"
INSIDE_CLEANUP_ROUTINE: "1"
INSIDE_FINISH_ROUTINE: "1"
INSIDE_USR1_HANDLER: "1"
INSIDE_USR2_HANDLER: "1"
INSIDE_BREAK_HANDLER: "1"
INSIDE_HUP_HANDLER: "1"
INSIDE_EXIT_HANDLER: "1"
INSIDE_QUIT_HANDLER: "1"
*** Parameter:
ALL_PARAMETER: "-D"
NOT_USED_PARAMETER: ""
FORCE: "1"
QUIET: "1"
VERBOSE: "1"
VERBOSE_LEVEL: "0"
USAGE_HELP: ""
LIST_FUNCTIONS_AND_EXIT: "1"
APPEND_LOG: "1"
LOG_STDOUT: "0"
*** Hostname variables:
CUR_HOST: "t540p"
CUR_SHORT_HOST: "t540p"
CUR_OS: "Linux"
*** Scriptname and directory:
SCRIPTNAME: "scriptt_mini.sh"
SCRIPTDIR: "."
REAL_SCRIPTDIR: "/data/develop/scripts"
REAL_SCRIPTNAME:
"/data/develop/scripts/scriptt_mini.sh"
*** Current environment:
CUR_SHELL: "/bin/ksh"
EDITOR: "/usr/bin/vi"
PAGER: "/usr/bin/less"
WORKING_DIR: "/data/develop/scripts"
LOGFILE: "/var/tmp/scriptt_mini.sh.log"
LOGFILE_FOUND: "1"
LOG_MESSAGE_CACHE: "
[28.02.2018 17:56 ] ### scriptt_mini.sh started at Wed Feb 28
17:56:46 CET 2018"
ROTATE_LOG: "0"
RUNNING_IN_TERMINAL_SESSION: "0"
KSH_VERSION: "93"
USE_ONLY_KSH88_FEATURES: "1"
TYPESET_F_SUPPORTED: "yes"
TRACE_FEATURE_SUPPORTED: "yes"
AWK: "awk"
ID: "id"
__PPID: "18416"
*** Variables for the function AskUser:
USER_INPUT: ""
LAST_USER_INPUT: ""
__NOECHO: "1"
__USE_TTY: "1"
__STTY_SETTINGS: ""
__DEBUG_SHELL_IN_ASKUSER: "0"
*** User and group:
CUR_USER_ID: "1000"
CUR_USER_NAME: "xtrnaw7"
CUR_GROUP_ID: "1000"
CUR_GROUP_NAME: "xtrnaw7"
*** RCM variables:
RCM_SERVICE: ""
RCM_FUNCTION: ""
RCM_HOSTID: ""
RCM_HOSTID_FILE: "/var/db/var/hostid"
RCM_DBQUERY: "/usr/db/RCM/Utility/dbquery"
RCM_DBGET_FILE: "/usr/db/RCM/Utility/dbgetfile"
RCM_USERID: ""
RCM_PASSWORD: ""
*** Housekeeping:
CLEANUP_FUNCTIONS: ""
FILES_TO_REMOVE:
"/tmp/scriptt_mini.sh.DebugShell.18785.1.tmp
/tmp/scriptt_mini.sh.DebugShell.18785.2.tmp"
DIRS_TO_REMOVE: ""
PROCS_TO_KILL: ""
KILL_PROC_TIMEOUT: "0"
FINISH_FUNCTIONS: ""
*** Debugging
__DEBUG_CODE: ""
__FUNCTION_INIT: "eval __settraps"
DEFAULT_DRYRUN_PREFIX: "echo "
PREFIX: ""
ENABLE_DEBUG: "0"
__TEE_OUTPUT_FILE:
"/var/tmp/scriptt_mini.sh.18785.tee.log"
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
To add variables to list for the alias vars add the variable names to list to the variable APPLICATION_VARIABLES. To add a string to print to that variable use
#message_to_print
Blanks are not allowed in the strings for APPLICATION_VARIABLES
but the alias will replace "_" with blanks in all lines that start
with a hash "#":
# Code:
#
----------------------------------------------------------------------
# main code starts here
#
APPLICATION_VARIABLES="
#These_are_my_application_variables
MyVAR1
MyVAR2
"
...
MyVAR1="Value aaa"
MyVAR2="Value bbb ccc"
...
# then in DebugShell
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> vars
*** constants
__TRUE: "0"
__FALSE: "1"
...
*** Housekeeping:
DIRS_TO_REMOVE: ""
FILES_TO_REMOVE: ""
PROCS_TO_KILL: ""
*** These are my application
variables
MyVAR1: "Value aaa"
MyVAR2: "Value bbb
ccc"
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
The alias functions
lists all defined functions known while executing the DebugShell:
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> functions
AskUser
check_rcm_values
cleanup
curtimestamp
DebugShell
__DebugShell
die
executeCommandAndLog
function_template
get_rcm_userid
isNumber
KillProcess
LogError
LogInfo
LogMsg
LogOnly
LogRuntimeInfo
LogWarning
print_runtime_variables
Read_APPL_PARAMS_entries
Retrieve_file_from_Jamaica
RotateLog
show_extended_usage_help
show_script_usage
signal_break_handler
signal_exit_handler
signal_hup_handler
signal_quit_handler
signal_usr1_handler
signal_usr2_handler
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
To view the source code of a function use "func <function_name>" (This works only if "typeset -f" is supported by your shell -- see above)
The parameter "fn" for the various aliase
can be one or more function names or a regex or both; use the
alias funcs to evaluate fn
for testing e.g.
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> funcs LogInfo
LogInfo
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> funcs Log*
LogError LogInfo LogMsg LogOnly LogRuntimeInfo
LogWarning
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> funcs Log* AskUser signal*
LogError LogInfo LogMsg LogOnly LogRuntimeInfo
LogWarning AskUser signal_break_handler signal_exit_handler
signal_hup_handler signal_quit_handler signal_usr1_handler
signal_usr2_handler
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> funcs *
AskUser check_rcm_values cleanup curtimestamp DebugShell
__DebugShell die __evaluate_fn executeCommandAndLog
function_template get_rcm_userid isNumber KillProcess LogError
LogInfo LogMsg LogOnly LogRuntimeInfo LogWarning
print_runtime_variables Read_APPL_PARAMS_entries
Retrieve_file_from_Jamaica RotateLog show_extended_usage_help
show_script_usage signal_break_handler signal_exit_handler
signal_hup_handler signal_quit_handler signal_usr1_handler
signal_usr2_handler
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> funcs all
AskUser check_rcm_values cleanup curtimestamp DebugShell
__DebugShell die __evaluate_fn executeCommandAndLog
function_template get_rcm_userid isNumber KillProcess LogError
LogInfo LogMsg LogOnly LogRuntimeInfo LogWarning
print_runtime_variables Read_APPL_PARAMS_entries
Retrieve_file_from_Jamaica RotateLog show_extended_usage_help
show_script_usage signal_break_handler signal_exit_handler
signal_hup_handler signal_quit_handler signal_usr1_handler
signal_usr2_handler
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> funcs signal_usr?_handler
signal_usr1_handler signal_usr2_handler
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> func this_function_does_not_exist
The function this_function_does_not_exist is not defined
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
To change the source code of a function in the running script
use the aliase editfunc, savefunc,
restorefunc, clearsavedfunc,
viewsavedfunc, and savedfuncs
(these aliase also only work if "typeset -f" is
supported by your shell)
The alias editfunc can be used to change
the source code of a function using the editor defined in the
environment variable EDITOR, e.g.
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> func isNumber
function isNumber {
typeset __FUNCTION="isNumber"
${__DEBUG_CODE}
${__FUNCTION_INIT}
typeset THISRC=${__FALSE}
# old code:
# typeset TESTVAR="$(echo "$1" | sed 's/[0-9]*//g' )"
# [ "${TESTVAR}"x = ""x ] && return ${__TRUE} ||
return ${__FALSE}
[[ $1 == +([0-9]) ]] && THISRC=${__TRUE} ||
THISRC=${__FALSE}
return ${THISRC}
}
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> isNumber 44
Executing now "eval isNumber 44" ...
---------
RC is 0
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> editfunc isNumber
Checking the new source code for "isNumber" using the shell
/bin/ksh now ...
Enabling the new source code for "isNumber" now ...
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> func isNumber
function isNumber {
typeset __FUNCTION="isNumber"
${__DEBUG_CODE}
${__FUNCTION_INIT}
typeset THISRC=${__FALSE}
# old code:
# typeset TESTVAR="$(echo "$1" | sed 's/[0-9]*//g' )"
# [ "${TESTVAR}"x = ""x ] && return ${__TRUE} ||
return ${__FALSE}
[[ $1 == +([0-9]) ]] && THISRC=${__TRUE} ||
THISRC=${__FALSE}
echo "*** Inside isFunc, the parameter are:
$*" >&2
return ${THISRC}
}
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> isNumber 44
Executing now "eval isNumber 44" ...
*** Inside isFunc, the parameter are: 44
---------
RC is 0
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
The alias editfunc can also be used to
define new functions, e.g.
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> editfunc isNumber1
The function isNumber1 is not defined
Create a new function "isNumber1" (y/N)? y
Checking the new source code for "isNumber1" using the shell
/bin/ksh now ...
Enabling the new source code for "isNumber1" now ...
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> func isNumber1
function isNumber1 {
typeset __FUNCTION="isNumber1"
${__DEBUG_CODE}
${__FUNCTION_INIT}
typeset THISRC=${__TRUE}
# add your code her
echo "This is the new function isNumber1"
return ${THISRC}
}
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
editfunc uses the function function_template
(if defined) as template for new functions.
editFunc uses the editor saved in the environment variable EDITOR; the default editor to use if the variable EDITOR is not defined is $( which vi ).
The aliase savefunc and restorefunc can be used to save and restore the current code for a function, e.g
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> func LogInfo
function LogInfo {
typeset __FUNCTION="LogInfo"
${__DEBUG_CODE}
${__FUNCTION_INIT}
[ ${VERBOSE} = ${__TRUE} ] && LogMsg "INFO: $*"
>&2
}
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> savefunc LogInfo
Saving the current code for the function LogInfo ...
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> editfunc LogInfo
Checking the new source code for "LogInfo" using the shell
/bin/ksh now ...
Enabling the new source code for "LogInfo" now ...
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> func LogInfo
function LogInfo {
typeset __FUNCTION="LogInfo"
${__DEBUG_CODE}
${__FUNCTION_INIT}
echo "*** Inside LogInfo ">&2
[ ${VERBOSE} = ${__TRUE} ] && LogMsg "INFO: $*"
>&2
}
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> LogInfo "Test Message"
Executing now "eval LogInfo "Test Message"" ...
*** Inside LogInfo
---------
RC is 1
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> restorefunc LogInfo
Restoring the code for the function LogInfo ...
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> func LogInfo
function LogInfo {
typeset __FUNCTION="LogInfo"
${__DEBUG_CODE}
${__FUNCTION_INIT}
[ ${VERBOSE} = ${__TRUE} ] && LogMsg "INFO: $*"
>&2
}
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> LogInfo "Test Message"
Executing now "eval LogInfo "Test Message"" ...
---------
RC is 1
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
The alias savefunc always saves the current code for a function (that might be already changed using editfunc). You can only save each function ones, e.g:
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> savedfuncs
Saved functions are: LogInfo
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> savefunc LogInfo
The function LogInfo is already saved
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
The alias viewsavedfunc lists the contents of a saved function using the view program defined in the environment variable PAGER, e.g
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute ("exit"
to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> PAGER=$( which cat )
Executing now "eval PAGER=$( which cat )" ...
---------
RC is 0
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute ("exit"
to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> viewsavedfunc curtimestamp
Viewing the code for the saved function curtimestamp ...
function curtimestamp {
typeset __FUNCTION="curtimestamp"
${__DEBUG_CODE}
${__FUNCTION_INIT}
date +%Y.%m.%d.%H_%M_%S_%s
}
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute ("exit"
to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
The default value for the variable PAGER if it's not defined is $( which less ) or, if less is not found $( which more ).
The alias savedfuncs lists all saved functions and the alias clearsavedfunc deletes a saved function, e.g:
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> savedfuncs
Saved functions are: LogInfo
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> clearsavedfunc LogInfo
Deleting the saved code for the function LogInfo ...
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> savedfuncs
There are no saved functions
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
You can use the aliase add_debug_code, view_debug, clear_debug, and set_debug to enable tracing
(set -x) for one or more functions (see the section Tracing Functions above for the
limitations of this feature)To temporary add the statement "${__DEBUG_CODE}" to a function manually while running the script you can use the alias add_debug_code (only if the shell supports this feature) , e.g:
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> func MyFunction2
function MyFunction2 {
typeset __FUNCTION="MyFunction2"
${__FUNCTION_INIT}
typeset THISRC=${__TRUE}
LogMsg "Inside of MyFunction2"
return ${THISRC}
}
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> add_debug_code MyFunction2
Adding debug code to the function MyFunction2 ...
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> func MyFunction2
function MyFunction2 { typeset
__FUNCTION=MyFunction2; ${__DEBUG_CODE};
typeset __FUNCTION="MyFunction2"
${__FUNCTION_INIT}
typeset THISRC=${__TRUE}
LogMsg "Inside of MyFunction2"
return ${THISRC}
}
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
Example for using set_debug:
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> view_debug
Debug code is currently enabled for these functions:
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> functions
AskUser
check_rcm_values
cleanup
curtimestamp
DebugShell
__DebugShell
die
__evaluate_fn
executeCommandAndLog
function_template
get_rcm_userid
isNumber
KillProcess
LogError
LogInfo
LogMsg
LogOnly
LogRuntimeInfo
LogWarning
print_runtime_variables
Read_APPL_PARAMS_entries
Retrieve_file_from_Jamaica
RotateLog
show_extended_usage_help
show_script_usage
signal_break_handler
signal_exit_handler
signal_hup_handler
signal_quit_handler
signal_usr1_handler
signal_usr2_handler
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> set_debug MyFunction LogWarning
Enabling debug code for the function(s) "MyFunction
LogWarning" now
Current settings for debug code are overwritten.
Enabling debug code for the function "MyFunction" ...
WARNING: The function "MyFunction" is not defined
Enabling debug code for the function "LogWarning" ...
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> view_debug
Debug code is currently enabled for these functions:
MyFunction LogWarning
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> LogWarning "Test Warning"
Executing now "eval LogWarning "Test Warning"" ...
*** Enabling trace for the function LogWarning ...
+ eval __settraps
+ LINENO=1
+ trap 'signal_hup_handler ${LINENO}' 1
+ trap 'signal_break_handler ${LINENO}' 2
+ trap 'signal_quit_handler ${LINENO}' 3
+ trap 'signal_exit_handler ${LINENO}' 15
+ trap 'signal_usr1_handler ${LINENO}' USR1
+ trap 'signal_usr2_handler ${LINENO}' USR2
+ LogMsg 'WARNING: Test Warning'
[03.03.2018 10:06 ] WARNING: Test Warning
---------
RC is 0
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> clear_debug
Clearing the debug code now ...
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> view_debug
Debug code is currently enabled for these functions:
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> LogWarning "Test Warning"
Executing now "eval LogWarning "Test Warning"" ...
[03.03.2018 10:07 ] WARNING: Test Warning
---------
RC is 0
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
set_debug will automatically add the statement "${__DEBUG_CODE}" to a function if it's missing and the feature is supported by the shell, e.g.:
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>> set_debug MyFunction2
Enabling debug code for the function(s) "MyFunction2" now
Adding debug code to the function MyFunction2
...
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to execute
("exit" to leave the shell)
Current environment: ksh version: 93 | change function code
supported: yes | tracing feature using $0 supported: yes
>>
Please note that set_debug
overwrites the variable __DEBUG_CODE and
therefor removes existing definitions.
To add additional functions to the existing list of functions
with debug code use a leading plus "+", e.g.
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to
execute ("exit" to leave the shell)
Current environment: ksh version: 93 | change
function code supported: yes | tracing feature using $0
supported: yes
>> set_debug signal_usr1_handler
signal_usr2_handler
Enabling debug code for the function(s) "
signal_usr1_handler signal_usr2_handler" now
Current settings for debug code are overwritten.
Enabling debug code for the function
"signal_usr1_handler" ...
Enabling debug code for the function
"signal_usr2_handler" ...
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to
execute ("exit" to leave the shell)
Current environment: ksh version: 93 | change
function code supported: yes | tracing feature using $0
supported: yes
>> view_debug
Debug code is currently enabled for these
functions:
signal_usr1_handler signal_usr2_handler
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to
execute ("exit" to leave the shell)
Current environment: ksh version: 93 | change
function code supported: yes | tracing feature using $0
supported: yes
>> set_debug +signal_quit_handler
Enabling debug code for the function(s)
"+signal_quit_handler" now
Current settings for debug code (
signal_usr1_handler signal_usr2_handler ) are preserved.
Enabling debug code for the function
"signal_usr1_handler" ...
Enabling debug code for the function
"signal_usr2_handler" ...
Enabling debug code for the function
"signal_quit_handler" ...
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to
execute ("exit" to leave the shell)
Current environment: ksh version: 93 | change
function code supported: yes | tracing feature using $0
supported: yes
>> view_debug
Debug code is currently enabled for these
functions:
signal_usr1_handler
signal_usr2_handler signal_quit_handler
-------------------------------------------------------------------------------
scriptt_mini.sh - debug shell - enter a command to
execute ("exit" to leave the shell)
Current environment: ksh version: 93 | change
function code supported: yes | tracing feature using $0
supported: yes
>>
Function |
Used for |
Comment |
BackupFile |
backup a file |
Usage: # BackupFile # # create a backup of a file if it exists # # usage: BackupFile sourcefile backupfile [backupfile_extension] # # returns: ${__TRUE} - backup created or original file does not exist # ${__FALSE} - error creating the backup # # |
isNumber |
check if a value is an number |
a value is a number if it
contains only the digits from 0 to 9 |
curstimestamp | write the current date and time to STDOUT | the output of curtimestamp
can be used in filenames |
AskUser |
ask the user
for a value If the parameter -y is used AskUser will always return ${__TRUE} without asking the user If the parameter -n is used AskUser will always return ${__FALSE} without asking the user The behaviour of AskUser can be changed using the variables __USE_TTY, __NOECHO, and __DEBUG_SHELL_IN_ASKUSER |
|
KillProcess |
kill one or more processes
using kill and kill -9, usage: KillProcess pid [...pid] |
The format for pid is
"pid[:timeout_in_seconds]" timeout_in_seconds is the time to wait after kill before a "kill -9" is issued if the process is still running; use "pid:-1" to disable the "kill -9" for a process Default timeout for all PIDs is KILL_PROC_TIMEOUT |
create_lock_file |
this function can be used to create a
semaphor file to avoid multiple running instances of the
script, e.g. create_lock_file /var/tmp/your_semaphor_file.lock # do whatever must be done while no other instance is runnig # and remove the lock file when done rm /var/tmp/your_semaphor_file.lock If the whole script should never run more then one time execute only create_lock_file /var/tmp/your_semaphor_file.lock at the beginning of your script. The semaphor file will the automatically deleted at script end in the house keeping code. |
the usage of the function is # create_lock_file # # function: create a lock file to avoid that multiple instances of this script are running at the same time # # usage: create_lock_file [lockfile] [wait_time] [wait_step_in_seconds] # # parameter: # lockfile - fully qualified name of the lock file # default: ${DEFAULT_LOCK_FILE} # # wait_time - time in seconds (#S), minutes (#M), or hours (#H) to wait if the lockfile already exist # default : ${DEFAULT_LOCK_FILE_WAIT_TIME} # # wait_step_in_seconds - wait pause in seconds # default: ${DEFAULT_STEP_COUNT} # # global varables used: # # WAIT_TIME_FOR_THE_LOCKFILE_IN_SECONDS # PID_OF_PROCESS_HOLDING_THE_LOCKFILE # # # returns: 0 - lock file created without waiting (probably after waiting for ${WAIT_TIME_FOR_THE_LOCKFILE_IN_SECONDS} seconds) # 1 - error creating the lock file # 2 - lock file already exists - could not create the lockfile, the variable # ${PID_OF_PROCESS_HOLDING_THE_LOCKFILE} contains the PID of the process holding the lockfile # 3 - usage error (invalid parameter, etc) # 3 - unknown error |
get_fqn | get the FQN of a file | |
gettime_in_seconds |
retrieve the number of seconds since 1.1.1970
|
this function uses perl |
read_file_section |
read the lines of a file between start_regex
and end_regex |
usage: read_file_section [filename]
[start_regex] [end_regex] |
is_variable_true | check if a variable is true (-> checks for
various values - see source code) |
|
convert_variable_to_boolean | convert a boolean variable to ${__TRUE} or ${__FALSE} | |
function_template | this is only a template for new functions | This function is used as template by the DebugShell alias editfunc for new functions if defined. |
check_rcm_values get_rcm_userid Read_APPL_PARAMS_entries Retrieve_file_from_Jamaica |
special functions for an RCM environment -- just ignore or delete these functions if not used |
#
----------------------------------------------------------------------
# function_template
#
# function:
#
# usage:
#
# returns: ${__TRUE} -
#
${__FALSE} -
#
function function_template {
typeset __FUNCTION="function_template"
${__FUNCTION_INIT}
${__DEBUG_CODE}
typeset THISRC=${__TRUE}
# add your code her
return ${THISRC}
}
The function function_template is used by the DebugShell alias editfunc if available - so you should not delete it.
http://bnsmb.de/solaris/scriptt.html |
scriptt.sh , a more complex
shell script template |
http://www.shelldorado.com/ |
Heiner's Shell Dorado |
http://apenwarr.ca/log/?m=201102#28 |
Insufficiently known POSIX shell features |
http://blog.fpmurphy.com/2008/10/ksh93-date-manipulation.html |
ksh93 builtin time formatting
with printf examples |
http://www.unix.com/unix-dummies-questions-answers/13018-exit-status-command-pipe-line.html#post47559 |
source for the function
executeCommandAndLog |
https://stackoverflow.com/questions/24412721/elegant-solution-to-implement-timeout-for-bash-commands-and-functions# |
code used for the function
runcmd_with_timeout |