This is a slowly growing collection of hopefully useful and reusable shell functions and patterns. https://code.jan.io/jan/jans_shell_utils
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
730B

  1. # Copyright (c) 2022 Jan Lehnardt <jan@apache.org>, MIT licensed
  2. . ./lib.sh
  3. wait_for_pid_exit () {
  4. assert_arg "$1" && pid="$1" || error_and_exit "pid not provided, exiting"
  5. assert_arg "$2" && iterations="$2" || iterations=3
  6. assert_arg "$3" && duration="$3" || duration=1
  7. debug "called wait_for_url(pid=pid, duration=$duration, iterations=$iterations)"
  8. waiting=0
  9. debug_inline "waiting for $pid to exit "
  10. until ( ! ps ax | grep $pid | grep -v grep > /dev/null); do
  11. if [ $waiting -eq $iterations ]; then
  12. let after=$duration*iterations
  13. debug_inline "failed, $pid still running after $after seconds\n"
  14. return 1
  15. fi
  16. debug_inline .
  17. let waiting=waiting+1
  18. sleep $duration
  19. done
  20. debug_inline " succeeded\n"
  21. }