----------------------------------------------------------------------------------------------------- scriptt.sh v1.0.0 Documentation - Examples ----------------------------------------------------------------------------------------------------- # create the documentation for the script ./scriptt.sh -H 2>./scriptt.sh.doc # get the verbose usage for the script ./scriptt.sh -v -v -h # write a config file for the script ./scriptt.sh -C # use another config file CONFIG_FILE=myconfig.conf ./scriptt.sh # use no config file at all CONFIG_FILE=none ./scriptt.sh # write all output (STDOUT and STDERR) to the file # /var/tmp/mylog.txt __TEE_OUTPUT_FILE=/var/tmp/mylog.txt ./scriptt.sh -T # create a dump of the environment variables in the files # /tmp/scriptt.sh.envvars.$$ # /tmp/scriptt.sh.exported_envvars.$$ # ($$ is the PID of the process running the script) __CREATE_DUMP=1 ./scriptt.sh # create a dump of the environment variables in the files # /var/tmp/debug/scriptt.sh.envvars.$$ # /var/tmp/debug/scriptt.sh.exported_envvars.\##EXAMPLE## # ($$ is the PID of the process running the script) # ($$ is the PID of the process running the script) __CREATE_DUMP=/var/tmp/debug ./scriptt.sh # Note: The variable __CREATE_DUMP can also be set with the debug parameter -D create_dump, e.g. scriptt.sh -D create_dump=/var/tmp/debug # use logger instead of echo to print the messages LOGMSG_FUNCTION="logger -s -p user.info ./scriptt.sh" ./scriptt.sh # Use -D setvar:varname=varvalue to set the value for one or more variables ./scriptt.sh -D setvar:NEWVAR=5 # use -D setvar:varname=varvalue to init the environment, print the internal variables and end the script ./scriptt.sh -D setvar:__PRINT_INTERNAL_VARIABLES=0 # use -D setvar:varname to enable debug infos for the parameter handling ./scriptt.sh -D setvar:__PRINT_ARGUMENTS=0 [your_script_parameter] # to temporary disable the house keeping at script end use ./scriptt.sh -D setvar:__NO_CLEANUP=0 # Note: to disable only parts of the house keeping use one of the variables: # __NO_EXIT_ROUTINES __NO_TEMPFILES_DELETE __NO_TEMPMOUNTS_UMOUNT # __NO_TEMPDIR_DELETE __NO_FINISH_ROUTINES __CLEANUP_ON_ERROR # __NO_KILL_PROCS # # Use -D tracefunc=x to trace the function GetSeconds ./scriptt.sh -D tracefunc=GetSeconds # Use -D tracefunc=x to trace the functions GetSeconds and CreateTemporaryFiles ./scriptt.sh -D tracefunc=GetSeconds,CreateTemporaryFiles # Use -D tracefunc=x to trace the functions GetSeconds, CreateTemporaryFiles, and SetEnvironment ./scriptt.sh -D tracefunc="GetSeconds CreateTemporaryFiles SetEnvironment" # Use -D debugcode=x to add some debug code to each function, e.g. to print the function name and parameter for each function executed use: ./scriptt.sh -D debugcode=" eval echo Entering the subroutine \${__FUNCTION} Parameter are \\\"\$*\\\" ... >/dev/tty " # Use -D debugcode=x to call a debug shell on every function start (note: use "kill -9 $$" while in the debug shell to end the script) ./scriptt.sh -D debugcode=" eval echo Entering the subroutine \${__FUNCTION} Parameter are \\\"\$*\\\" ... >/dev/tty ; DebugShell " # Use -D debugcode=x to call a debug shell for every call of the function LogInfo (note: use "kill -9 $$" while in the debug shell to end the script) ./scriptt.sh -D debugcode=" eval echo Entering the subroutine \${__FUNCTION} Parameter are \\\"\$*\\\" ... >/dev/tty ; [ \${__FUNCTION} = LogInfo ] && DebugShell " # use -D debugcode=x to enable tracing (set -x) for the function GetSeconds only ./scriptt.sh -D debugcode=" eval echo Entering the subroutine \${__FUNCTION} Parameter are \\\"\$*\\\" ... >/dev/tty ; [ \${__FUNCTION} = GetSeconds ] && set -x" # for more complicated code you should use an include file , e.g. ls -l debugcode -rwxr-xr-x. 1 xtrnaw7 xtrnaw7 325 31. Okt 19:34 debugcode cat debugcode echo "Entering the subroutine ${__FUNCTION} Parameter are \"$*\" ... " >/dev/tty ; if [ ${__FUNCTION} = GetSeconds ] ; then echo "Enabling trace for GetSconds:" >/dev/tty set -x elif [ ${__FUNCTION} = CreateTemporaryFiles ] ; then echo "Calling DebugShell from CreateTemporyFiles ..." >/dev/tty DebugShell fi ./scriptt.sh -D debugcode=". $PWD/debugcode" # Notes Use the parameter -D debugcode=x with care! And do NOT use code that writes to STDOUT - all output must go to another file handle, e.g STDERR or /dev/tty! Use either -D debugcode=x or -D tracefunc=f1 -- but not both