From 566dfc1852216acad83272d9216858f44d5ce26f Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Tue, 18 Aug 2015 11:08:03 +0200 Subject: [PATCH] Streamline and document exit codes --- README.md | 11 +++++++++++ bin/backup-script | 13 ++++++------- bin/backup-script-wrapper | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d5c6f54..f816c05 100644 --- a/README.md +++ b/README.md @@ -151,3 +151,14 @@ definition files are automatically mapped to the new backup-script variables: * source -> source_root * pre_exec -> job_pre_exec * post_exec -> job_post_exec + + +## Exit codes + +- 1: Unspecific Error! +- 2: Usage information has been shown. +- 3: Can't read system definition +- 4: PID-file exists! +- 5: Pre-exec command failed! +- 6: There have been systems with errors! +- 9: Aborted (CTRL-C)! diff --git a/bin/backup-script b/bin/backup-script index 7699b58..2b9f7d7 100755 --- a/bin/backup-script +++ b/bin/backup-script @@ -55,7 +55,7 @@ Usage() { echo "Configuration file is \"$conf\"," echo "using \"$conf_d\" as configuration directory." echo - exit 1 + exit 2 } CleanUp() { @@ -306,7 +306,7 @@ if [ $# -ge 1 ]; then for s in "$@"; do if [ ! -r "${conf_d}/$s" ]; then echo "$NAME: Can' read \"${conf_d}/$s\"!" - exit 1 + exit 3 fi sys="$sys ${conf_d}/$s" done @@ -321,7 +321,7 @@ if [ -e "$PIDFILE" ]; then echo echo -n "Aborted: "; date echo - exit 3 + exit 4 fi touch "$PIDFILE" 2>/dev/null if [ $? -ne 0 ]; then @@ -338,7 +338,7 @@ if [ -n "$pre_exec" ]; then echo "Error: pre-exec command failed!"; echo CleanUp echo "Aborting backup."; echo - exit 2 + exit 5 fi sleep 2 echo @@ -557,8 +557,7 @@ for f in $sys; do if [ $ret -eq 20 ]; then echo "Backup of \"$system\" interrupted. Aborting ..." - CleanUp - exit 1 + GotSignal fi echo -n "End date: "; date @@ -639,7 +638,7 @@ echo if [ $count_started -ne $count_ok ]; then echo "-----> THERE HAVE BEEN ERRORS! <-----" echo - exit 1 + exit 6 fi # -eof- diff --git a/bin/backup-script-wrapper b/bin/backup-script-wrapper index fbd061f..62c04b0 100755 --- a/bin/backup-script-wrapper +++ b/bin/backup-script-wrapper @@ -22,7 +22,7 @@ fi NAME="backup-script" HOST=`hostname` -TMP=`mktemp /tmp/$NAME.XXXXXXXX` || exit 11 +TMP=`mktemp /tmp/$NAME.XXXXXXXX` || exit 1 LOGFILE="/var/log/backup-script.log" PATH="$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" -- 2.39.2