A Script Template and Useful Techniques for ksh Scripts
http://www.sun.com/bigadmin/content/submitted/ksh_script_template.jsp
Note
16.10.2011: The link above does not work anymore.
see also the comments for the script
template in the wiki:
Version |
Releasedate |
Description
|
The 1.x version of scriptt.sh is NOT updated
anymore. The current version of scriptt.sh is v2.x |
||
1.22.46 |
27.04.2013 |
#### 1.22.46 27.04.2013
/bs #### executeCommandAndLog rewritten using coprocesses (see also credits) #### Info update: executeCommandAndLog does now return the RC of the executed #### command even if a logfile is defined |
1.22.45 |
07.06.2012 |
#### 1.22.45 07.06.2012
/bs #### added code to check if the symbolic link for the lockfile already exists before creating #### the lock file |
1.22.44 |
22.04.2012 |
#### 1.22.44 22.04.2012 #### The script now uses nawk only if available (if not awk is used) #### variables are now supported in the usage examples (prefixed with ##EXAMPLE##) #### add a line with the current date and time to variable dumps, e.g. #### #### ### /var/tmp/scriptt.sh.exported_envvars.dump_no_0_20074 - exported environment variable dump created on Sun Apr 22 11:35:38 CEST 2012 #### #### ### /var/tmp/scriptt.sh.envvars.dump_no_0_20074 - environment variable dump created on Sun Apr 22 11:35:38 CEST 2012 #### added experimental interactive mode to the signal handler for USR2 #### replaced /usr/bin/echo with printf #### added the variable LOGMSG_FUNCTION |
1.22.43 |
15.10.2011 |
#### 1.22.43 15.10.2011 #### added support for disabling the config file feature CONFIG_FILE=none ./scriptt.sh #### corrected a minor bug in SaveEnvironmentVariables #### corrected a bug in the function SaveEnvironmentVariables #### corrected a bug in getting the value for the variable ${__ABSOLUTE_SCRIPTDIR} #### |
1.22.42 |
05.10.2011 |
#### 1.22.41 26.09.2011 #### added the parameter -X #### disabled some ksh93 code because "ksh -x -n" using ksh88 does not like it #### #### 1.22.42 05.10.2011 #### added the function PrintDotToSTDOUT |
1.22.40 | 25.07.20111 |
#### 1.22.39 24.07.2011 #### __INIT_FUNCTION now enable for cygwin also #### __SHELL did not work in all Unixes - fixed #### __OS_FULLNAME is now also set in Solaris and Linux #### #### 1.22.40 25.07.2011 #### added some code for ksh93 (functions: substr) #### Note: set __USE_ONLY_KSH88_FEATURES to ${__TRUE} to suppress using the ksh93 features #### The default action for the signal handler USR1 is now "Create an env dump in /var/tmp" #### The filenames for the dumps are #### #### /var/tmp/<scriptname>.envvars.dump_no_<no>_<PID> #### /var/tmp/<scriptname>.exported_envvars.dump_no_<no>_<PID> #### #### where <no> is a sequential number, <PID> is the PID of the process with the script, #### and <scriptname> is the name of the script without the path. #### |
1.22.38 |
22.07.2011 |
#### 1.22.38 22.07.2011 #### added code to make the trap handling also work in bash #### added a sample user defined trap handler (function USER_SIGNAL_HANDLER) #### added the function SetHousekeeping to enabe or disable house keeping #### scriptt.sh did not write all messages to the logfile if a relative filename was used - fixed #### added more help text for "-v -v -v -h" #### now user defined signal handler can have arguments #### the RBAC feature (__USE_RBAC) did not work as expected - fixed #### added new scriptt testsuite for testing the script template on other OS and/or shells #### added the function SaveEnvironmentVariables #### |
1.22.37 |
08.07.2011 |
## 1.22.37 08.07.2011 ## corrected a minor error with the QUIET parameter ## added code to dump the environment (env var __CREATE_DUMP, function CreateDump ) ## implemented work around for missing function whence in bash ## added the function LogIfNotVerbose ## |
1.22.36 |
11.04.2009 |
## 1.22.32
04.04.2008 /bs ## minor changes for zone support ## ## 1.22.33 12.02.2009 /bs ## disabled the usage of prtdiag due to the fact that prtdiag on newer Sun machines needs a long time to run ## (-> __MACHINE_SUBTYPE is now always empty for Solaris machines) ## added the variable __CONFIG_FILE_FOUND; this variable contains the name of the config file ## read if a config file was found ## added the variable __CONFIG_FILE_VERSION ## ## 1.22.34 28.02.2009 /bs ## added code to check for the max. line no for the debug handler ## (an array in ksh88 can only handle up to 4096 entries) ## added the variable __PIDFILE ## ## 1.22.35 06.04.2009 /bs ## added the variables ## __NO_CLEANUP ## __NO_EXIT_ROUTINES ## __NO_TEMPFILES_DELETE ## __NO_TEMPMOUNTS_UMOUNT ## __NO_TEMPDIR_DELETE ## __NO_FINISH_ROUTINES ## __CLEANUP_ON_ERROR ## CONFIG_FILE ## ## 1.22.36 11.04.2009 /bs ## corrected a cosmetic error in the messages (wrong: ${TEMPFILE#} correct: ${__TEMPFILE#}) ## |
1.22.33 |
12.02.2009 |
## 1.22.31
18.03.2008 /bs ## added the version number to the start and end messages ## an existing config file is now removed (and not read) if the script is called with -C to create a config file ## ## 1.22.32 04.04.2008 /bs ## minor changes for zone support ## ## 1.22.33 12.02.2009 /bs ## disabled the usage of prtdiag due to the fact that prtdiag on newer Sun machines needs a long time to run ## (-> __MACHINE_SUBTYPE is now always empty for Solaris machines) ## added the variable __CONFIG_FILE_FOUND; this variable contains the name of the config file ## read if a config file was found ## added the variable __CONFIG_FILE_VERSION |
1.22.30 | 28.02.2008 /bs | ## 1.22.28
12.01.2008 /bs ## corrected a syntax error in the show usage routine ## added the function PrintWithTimestamp (see credits above) ## ## 1.22.29 31.01.2008 /bs ## there was a bug in the new code to remove the lockfile which prevented ## the script from removing the lockfile at program end ## if the lockfile already exist the script printed not the correct error ## message ## ## 1.22.30 28.02.2008 /bs ## Info update: executeCommandAndLog does NOT return the RC of the executed ## command if a logfile is defined ## added inital support for CYGWIN ## (tested with CYGWIN_NT-5.1 v..1.5.20(0.156/4/2) ## Most of the internal functions are NOT tested yet in CYGWIN ## GetCurrentUID now supports UIDs greater than 254; the function now prints the UID to STDOUT ## Corrected bug in GetUserName (only a workaround, not the solution) ## now using printf in the AskUserRoutine |
1.22.27 |
29.12.2007 /bs |
## ## 1.22.24 05.10.2007 /bs ## another minor fix for ksh93 compatibility ## ## 1.22.25 08.10.2007 /bs ## only spelling errors corrected ## ## 1.22.26 19.11.2007 /bs ## only spelling errors corrected ## ## 1.22.27 29.12.2007 /bs ## improved the code to create the lockfile (thanks to wpollock for the info; see ## credits above) ## improved the code to create the temporary files (thanks to wpollock for the info; see ## credits above) ## added the function rand (thanks to wpollock for the info; see credits above) ## the script now uses the directory name saved in the variable $TMPDIR for temporary files ## if it's defined ## now the umask used for creating temporary files can be changed (via variable __TEMPFILE_UMASK) see this wiki entry |
1.22.23 | 25.09.2007 /bs | 1.22.20
12.09.2007 /bs the script now checks the ksh version if running on Solaris made some changes for compability with ksh93 1.22.21 18.09.2007 /bs (BigAdmin Version 2) added the variable __FINISHROUTINES changed __REQUIRED_ZONE to __REQUIRED_ZONES added the variable __KSH_VERSION reworked the trap handling 1.22.22 23.09.2007 /bs added the signal handling for SIGUSR1 and SIGUSR2 (variables __SIGUSR1_FUNC and __SIGUSR2_FUNC) added user defined function for the signals HUP, BREAK, TERM, QUIT, EXIT, USR1 and USR2 added the variables __WARNING_PREFIX, __ERROR_PREFIX, __INFO_PREFIX, and __RUNTIME_INFO_PREFIX the parameter -T or --tee can now be on any position in the parameters the default output file if called with -T or --tee is now /var/tmp/${0##*/}.$$.tee.log 1.22.23 25.09.2007 /bs added the environment variables __INFO_PREFIX, __WARNING_PREFIX, __ERROR_PREFIX, and __RUNTIME_INFO_PREFIX added the environment variable __DEBUG_HISTFILE reworked the function to print the usage help : use "-h -v" to view the extented usage help and use "-h -v -v" to view the environment variables used also |
1.22.19 |
08/04/2007 |
1.22.16
05.07.2007 /bs enhanced initial support for other Operating Systems Support for other OS is still not fully tested! 1.22.17 06.07.2007 /bs added the global variable __TRAP_SIGNAL 1.22.18 01.08.2007 /bs __OS_VERSION and __OS_RELEASE were not set - corrected 1.22.19 04.08.2007 /bs wrong function used to print "__TRAP_SIGNAL is \"${__TRAP_SIGNAL}\"" - fixed |
1.22.15 |
11/23/2006 |
1.22.11
19.10.2006 /bs corrected a minor bug in AskUser (/c was not interpreted by echo) corrected a bug in the handling of the parameter -S (-S was ignored) 1.22.12 31.10.2006 /bs added the variable __REQUIRED_ZONE 1.22.13 13.11.2006 /bs the template now uses TMP or TEMP if set for the temporary files 1.22.14 14.11.2006 /bs corrected a bug in the function AskUser (the default was y not n) 1.22.15 21.11.2006 /bs added initial support for other Operating Systems corrected some bugs in the debug handler |
1.22.10 |
09/20/2006 |
1.22.4
06.07.2006 /bs corrected a bug in the parameter error handling routine 1.22.5 27.07.2006 /bs corrected some minor bugs 1.22.6 09.08.2006 /bs corrected some minor bugs 1.22.7 17.08.2006 /bs add the CheckParameterCount function added the parameter -T added long parameter support (e.g --help) 1.22.8 07.09.2006 /bs added code to save the env variable LANG and set it temporary to C 1.22.9 20.09.2006 /bs corrected code to save the env variable LANG and set it temporary to C 1.22.10 21.09.2006 /bs cleanup comments the number of temporary files created automatically is now variable (see the variable __NO_OF_TEMPFILES) added code to install the trap handler in all functions |
1.22.3 |
06/24/2006 |
1.22.2.
21.06.2006 /bs added the parameter -V added the use of environemnt variables added the variable __NO_TIME_STAMPS added the variable __NO_HEADERS corrected a bug in the function executeCommandAndLogSTDERR added missing return commands 1.22.3 24.06.2006 /bs added the function StartStop_LogAll_to_logfile added the variable __USE_TTY (used in AskUser) corrected an spelling error (dev/nul instead of /dev/null) |
1.20.0 |
08/01/2005 |
some enhancements and bug
fixes |
1.18.2 |
03/18/2005 | minor bug fixes |
1.18.0 |
02/02/2005 |
see also the documentation
OS |
Shell |
Date |
scriptt
version |
TestSuite
version |
Result |
Tests
failed |
Solaris x86 U9 Generic_142910-17 |
/usr/bin/ksh |
24.07.2011 |
1.22.39 24.07.2011 |
2.0.0 17.07.2011/bs |
all ok |
- |
Solaris x86 U9 Generic_142910-17 |
/usr/db/bin/dtksh |
24.07.2011 |
1.22.39 24.07.2011 | 2.0.0 17.07.2011/bs | mostly ok |
long_parameter_test |
Solaris x86 U9 Generic_142910-17 |
/usr/xpg4/bin/sh |
24.07.2011 |
1.22.39 24.07.2011 | 2.0.0 17.07.2011/bs | mostly ok | long_parameter_test |
Solaris x86 U9 Generic_142910-17 |
/usr/bin/bash |
24.07.2011 |
1.22.39 24.07.2011 | 2.0.0 17.07.2011/bs | not ok |
long_parameter_test syntax_error_test_004 tee_test_001 |
Linux 2.6.32-33-generic-pae #70-Ubuntu SMP Thu Jul 7 22:51:12 UTC 2011 i686 GNU/Linux |
/usr/bin/ksh |
24.07.2011 |
1.22.39 24.07.2011 | 2.0.0 17.07.2011/bs | mostly ok |
long_parameter_test |
Linux 2.6.32-33-generic-pae #70-Ubuntu SMP Thu Jul 7 22:51:12 UTC 2011 i686 GNU/Linux |
/bin/bash |
24.07.2011 | 1.22.39 24.07.2011 | 2.0.0 17.07.2011/bs | not ok |
long_parameter_test syntax_error_test_004 tee_test_001 |
Solaris 9 4/04 s9s_u6wos_08a
SPARC "Generic_122300-08 |
/usr/bin/ksh |
26.07.2011 |
1.22.40 25.07.2011 |
2.0.0 17.07.2011/bs | mostly ok |
|
AIX 5.3 |
/usr/bin/ksh |
26.07.2011 |
1.22.40 25.07.2011 |
2.0.0 17.07.2011/bs | not ok |
long_parameter_test syntax_error_test_004 |
scriptt.sh is v2.x | scriptt.sh v2.x |
http://www.tramm.li/iWiki/ShellTipps.html |
Shell Tips |
http://www.shelldorado.com/ |
Heiner's Shell Dorado |
http://apenwarr.ca/log/?m=201102#28 |
Insufficiently known POSIX shell features |