default_ping=1
default_local=0
default_generations=0
+default_job_pre_exec=""
+default_job_post_exec=""
Usage() {
echo "Usage: $NAME [<options>] [<system> [<system> [...]]]"
exit 9
}
+ExecJob() {
+ what="$1"
+ cmd="$2"
+
+ echo "Running job ${what}-exec command ..."
+ [ "$local" -eq 0 ] \
+ && cmd="$ssh_cmd ${user}@${system} $cmd"
+ echo -n "Start date (${what}-exec): "; date
+ echo "$cmd"
+ if [ "$DRYRUN" -eq 0 ]; then
+ $SHELL -c "$cmd"; ret=$?
+ else
+ echo " *** Trial run, not executing ${what}-exec command!"
+ ret=0
+ fi
+ [ $ret -eq 0 ] \
+ && echo "The ${what}-exec command completed with status 0, OK." \
+ || echo "The ${what}-exec command completed with ERRORS, code $ret!"
+ return $ret
+}
+
while [ $# -gt 0 ]; do
case "$1" in
"-n"|"--dry-run")
ping="$default_ping"
local="$default_local"
generations="$default_generations"
+ job_pre_exec="$default_job_pre_exec"
+ job_post_exec="$default_job_post_exec"
# Read in system configuration file
source "$f"
ssh_cmd="ssh"
[ -n "$ssh_args_add" ] && ssh_cmd="$ssh_cmd $ssh_args_add"
+ # execute job "pre-exec" command, if any
+ if [ -n "$job_pre_exec" ]; then
+ ExecJob pre "$job_pre_exec" ; ret=$?
+ if [ $ret -ne 0 ]; then
+ [ $ret -ne 99 ] && count_started=$count_started+1
+ echo "Pre-exec command failed, \"$system\" skipped!"
+ echo; continue
+ fi
+ fi
+
+ # prepare (remote) command ...
cmd="rsync --archive"
[ "$compress" -ne 0 ] && cmd="$cmd --compress"
cmd="$cmd --rsh=\"$ssh_cmd\" --delete --delete-excluded --sparse"
echo "System \"$system\" completed with ERRORS, code $ret!"
fi
+ # execute job "post-exec" command, if any
+ if [ -n "$job_post_exec" ]; then
+ ExecJob post "$job_post_exec"
+ fi
+
# Clean up old generations
if [ $generations -gt 0 ]; then
sys_target="$target/$fname"