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.

26 lines
665B

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