Last active
November 10, 2019 00:08
-
-
Save RonanKER/5701335f254bba9e795ef5843e8bdb8a to your computer and use it in GitHub Desktop.
shell script execution "framework" - centralize head&tail of a bunch of scripts & externalise context parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export SRC_DATA_DIR=/home/user/source | |
export DEST_DATA_DIR=/home/user/destination | |
export DATE_EXEC=${DATE_EXEC:-$(date +%Y%m%d_%H%M%S)} | |
export TMP_DIR=/tmp/myscripttmpdir | |
export LOGS_DIR=$SCRIPT_DIR/logs | |
export SRC_DB_USER=user | |
export SRC_DB_PASSWD=password | |
export SRC_DB_NAME=db1 | |
export DEST_DB_USER=user | |
export DEST_DB_PASSWD=password | |
export DEST_DB_NAME=db2 | |
export JAVA_HOME=/usr/local/java/jdk7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "End $SCRIPT_NAME : $(date +%Y%m%d_%H%M%S)" | |
trap - EXIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
export SCRIPT_NAME="Exemple" | |
source "$SCRIPT_DIR/init.shf" | |
# - - - | |
echo "Exemple script" | |
echo "$SRC_DATA_DIR -> $DEST_DATA_DIR" | |
echo "DB $SRC_DB_NAME -> $DEST_DB_NAME" | |
# - - - | |
source "$SCRIPT_DIR/end.shf" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
err_report() { | |
echo "$(date +%Y%m%d_%H%M%S): Error occured on line $1 : $2 $3" | |
} | |
trap 'err_report $LINENO $BASH_COMMAND $*' EXIT | |
set -e | |
export DATE_EXEC=${DATE_EXEC:-$(date +%Y%m%d_%H%M%S)} | |
source "$SCRIPT_DIR/context.prop" | |
mkdir -p $LOGS_DIR $TMP_DIR | |
# copy stdout/stderr to logs files | |
exec > >(tee -ia $LOGS_DIR/$SCRIPT_NAME-$DATE_EXEC-out.log) | |
exec 2> >(tee -ia $LOGS_DIR/$SCRIPT_NAME-$DATE_EXEC-err.log >&2) | |
echo "Start $SCRIPT_NAME : $DATE_EXEC" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment