Spring批处理Shell脚本通过状态

时间:2019-03-21 11:36:36

标签: spring shell spring-batch

我想知道春季批处理如何将作业状态(已完成或失败)发送到shell脚本,以便他开始治疗。 谢谢。

2 个答案:

答案 0 :(得分:1)

我有一个示例,该示例是捕获从Shell脚本调用的spring批处理中的退出代码。

JOB_RET = $?。

希望有帮助。

    #!/bin/bash
#
#  Launch Spring Batch
#
#Get the absolute path to the folder containing the folder this script is located in
BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HOME_DIR=$(dirname $BIN_DIR)
BATCH_HOME=$HOME_DIR
RUN_ID=$(date +"%Y-%m-%d %H:%M:%S")
LOG4J_CONF=file:$HOME_DIR/config/log4j.xml

function show_help {
    echo "usage:  $BASH_SOURCE -o <options> -d <month> -y <year>"
    echo "             where command is one of the following: "
    echo "                   options                    - Options (such as autoLogin|autoLogOut)."
    echo "                   month                      - Enter a month as Job param."
    echo "                   year                       - Enter a year as Job param."
    exit 1
}

# Read command line options
OPTIND=1         # Reset in case getopts has been used previously in the shell.
while getopts "ho:d:y:" opt; do
    case "$opt" in
    h)
        show_help
        exit 0
        ;;
    d)  options=$OPTARG
        ;;
    s)  month=$OPTARG
        ;;
    o)  year=$OPTARG
        ;;
    esac
done

JOB_PARAMS="options=$options month=$month year=$year"

#Run the job
$JAVA_HOME -cp "$(echo $HOME_DIR/lib/*.jar | tr ' ' ':') \
        -Djava.security.properties==$JAVA_SECURITY_FILE \
        -Dlog4j.configuration=$LOG4J_CONF \
        -DBATCH_HOME=$HOME_DIR -d64 \
               org.springframework.batch.core.launch.support.CommandLineJobRunner batch-jobs.xml <job-name> run.id="$RUN_ID" ${JOB_PARAMS} > $HOME_DIR/logs/stdout.log 2>&1

JOB_RET=$?
echo "Job returns $JOB_RET" >> $HOME_DIR/logs/stdout.log
exit $JOB_RET

https://bigzidane.wordpress.com/2016/06/26/launch-spring-batch-job-from-shell-script-sh/

答案 1 :(得分:0)

您正在寻找ExitCodeMapper。它将作业的退出代码映射到一个整数,该整数将是运行作业的JVM的退出代码。

如果您从Shell脚本运行作业,则此退出代码将是脚本返回的值。