run_mark_stdout() { # Based on the run function, additional information is added to # each line of output(program info) # to capture function output, use this function carefully einfo "Executing: $*" local mark="${1}" shift 1 # mark="$(awk '{print $1}' <<< "$*" | awk -F '/' '{print $NF}')" "$@" 2>&1 | stdbuf --output=L sed "s/^/[${mark}] /" }
set +e for pkg_info in"${pkgs_info[@]}"; do if grep -q "SYSTEM/" <<< "${pkg_info}"; then echo"${pkg_info}" >&999 else echo"${pkg_info}" >&777 fi done run_mark_stdout "YANG" process "777" & run_mark_stdout "YNC" process "999" & ignore_error="no" wait_and_return $(jobs -p) }
analyze_with_timeout() { local analyze_duration="${1}" local kill_after="${2}" must_have_var analyze_duration kill_after
shift 2 einfo "Executing: $*" if [[ "${JOB_NAME}" =~ .*_verify ]]; then timeout --kill-after=${kill_after}"${analyze_duration}""$@" || { ewarn "analyze timeout, skip verify." exit 0 } else "$@" fi }
timeout参数说明: analyze_duration: kill the command if still running after analyze_duration kill_after: also send a KILL signal if command is still running this long after the initial signal was sent