2019-02-27 21:48:37 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2019-08-20 19:45:41 +00:00
|
|
|
TIMEOUT=${1}
|
|
|
|
shift
|
2019-11-30 09:57:29 +00:00
|
|
|
PGREP_FILTER=${@}
|
2019-02-27 21:48:37 +00:00
|
|
|
SLEEP_SEC=5
|
|
|
|
STEPS=$((TIMEOUT / SLEEP_SEC))
|
2019-11-30 09:57:29 +00:00
|
|
|
# use UID to restrict search
|
|
|
|
PGREP_OPTS="-U ${UID} -f"
|
2019-02-27 21:48:37 +00:00
|
|
|
|
2019-08-20 19:45:41 +00:00
|
|
|
if [[ -z ${PGREP_OPTS} ]]; then
|
|
|
|
echo "No pgrep options name specified!" >&2
|
2019-02-27 21:48:37 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-11-30 09:57:29 +00:00
|
|
|
echo "Checking for process: '${PGREP_FILTER}'"
|
2019-02-27 21:48:37 +00:00
|
|
|
for ((i = 0; i < ${STEPS}; i += 1)); do
|
2019-11-30 09:57:29 +00:00
|
|
|
if pgrep ${PGREP_OPTS} "${PGREP_FILTER}" > /dev/null; then
|
2019-02-27 21:48:37 +00:00
|
|
|
echo "Process found. Sleeping ${SLEEP_SEC}..." >&2
|
|
|
|
sleep ${SLEEP_SEC}
|
|
|
|
else
|
2019-11-30 09:57:29 +00:00
|
|
|
echo "Process '${PGREP_FILTER}' gone." >&2
|
2019-02-27 21:48:37 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2019-08-20 19:45:41 +00:00
|
|
|
echo "Timeout reached! (${TIMEOUT}s) Process still up: ${PGREP_OPTS}" >&2
|
2019-11-30 09:57:29 +00:00
|
|
|
echo "Following processes matched:"
|
|
|
|
# show what is still up
|
|
|
|
ps u $(pgrep -l ${PGREP_OPTS} "${PGREP_FILTER}" | cut -d' ' -f1 | xargs -I{} echo -n "-p {} ")
|
2019-02-27 21:48:37 +00:00
|
|
|
exit 1
|