Bashinator: Bash Shell Script Framework
Bashinator is a framework for bash shell scripts.
Features:
- Flexible and powerful message handling: print, log (to syslog and/or logfile) and mail messages (configureable based on severity) with a single message function, for example:
- Log messages from debug...alert, print messages from info...alert, mail messages from warning...alert
- Log and mail messages with timestamps, print messages without timestamps
- Log to syslog and logfile at once, overwrite or append to the logfile
- Colored output (if printed to a terminal supporting colors, redirected output is not colored)
- Exhaustive information (timestamps, message severity, source file, line numbers and function names) in messages to ease debugging
- Function call stack traces
- Logging of sub-command output (capturing stdout/stderr of external commands to a dedicated temporary logfile)
- Lockfile handling
- ...and more.
Quickstart
On Gentoo Linux:
# add the wschlich overlay
layman -a wschlich
# install bashinator
emerge bashinator
# install the bashinator example application from the doc directory to the standard location
install -D -o root -g root -m 0644 /usr/share/doc/bashinator-*/example/bashinator.cfg.sh /etc/example/bashinator.cfg.sh
install -D -o root -g root -m 0644 /usr/share/doc/bashinator-*/example/example.cfg.sh /etc/example/example.cfg.sh
install -D -o root -g root -m 0644 /usr/share/doc/bashinator-*/example/example.lib.sh /etc/example/example.lib.sh
install -D -o root -g root -m 0755 /usr/share/doc/bashinator-*/example/example.sh /usr/bin/example.sh
# run the example script
/usr/local/bin/example.sh -a
On any other Linux:
# download a bashinator release and unpack the package
wget http://www.bashinator.org/releases/bashinator-0.4.tar.bz2
tar -xjvf bashinator-*.tar.bz2
# install the bashinator library and the example application to the standard location
install -D -o root -g root -m 0644 bashinator-*/bashinator.lib.0.sh /usr/lib/bashinator.lib.0.sh
install -D -o root -g root -m 0644 bashinator-*/example/bashinator.cfg.sh /etc/example/bashinator.cfg.sh
install -D -o root -g root -m 0644 bashinator-*/example/example.cfg.sh /etc/example/example.cfg.sh
install -D -o root -g root -m 0644 bashinator-*/example/example.lib.sh /usr/lib/example.lib.sh
install -D -o root -g root -m 0755 bashinator-*/example/example.sh /usr/bin/example.sh
# run the example script
/usr/local/bin/example.sh -a
Documentation
A typical Bashinator-based application file layout looks like this:
- /etc/myapplication/bashinator.cfg.sh # bashinator configuration file
- /etc/myapplication/myapplication.cfg.sh # application configuration file
- /usr/lib/myapplication.lib.sh # application library file containing __init(), __main() and other user defined functions
- /usr/bin/myapplication.sh # executable application script file based on bashinators example.sh
A typical Bashinator-based application script structure looks like this (see example.sh):
- define basic bashinator variables
- source bashinator library + config
- source application library + config
- boot bashinator via __boot()
- dispatch the application via __dispatch()
- runs __init(): initializes application (command line parsing, argument validation etc.). this function must be defined by the user!
- runs __prepare(): creates sub-command logfile (if configured), checks for and creates lockfile (if configured). this function is defined by bashinator.
- runs __main(): the main application code. this function must be defined by the user!
- runs __cleanup(): removes sub-command logfile (if configured), removes lockfile (if configured). this function is defined by bashinator.
Files
Screenshots
Messages of example.sh printed on terminal:
Messages of example.sh sent via mail:
Projects based on Bashinator
Bashinator on the web
Other bash frameworks
Contact/Imprint
Wolfram Schlich
Last modified: 16. February 2010, 14:19:11 by Wolfram Schlich <wschlich*AT*gentoo*DOT*org>