Browse Source

feat: exorcise bashisms

main
Jan Lehnardt 2 years ago
parent
commit
8b4923ccaa
3 changed files with 6 additions and 8 deletions
  1. +2
    -4
      README.md
  2. +2
    -2
      wait_for_pid_exit.sh
  3. +2
    -2
      wait_for_url.sh

+ 2
- 4
README.md View File

@@ -4,6 +4,8 @@ I’m coming across having to write the same shell script bits occasionally, and

This is a *slowly* growing collection of hopefully useful and reusable shell functions and patterns.

Currently tested in macOS only.

Copyright (c) 2022 Jan Lehnardt <jan@apache.org>, MIT licensed

## Goals
@@ -29,8 +31,6 @@ This section documents reusable functions for your scripts.

Wait for a particular URL to be available using `curl`. Wait `$duration` seconds between attempts, try `$iterations` times. Defaults to `1` seconds and `3` times.

Requires `bash`.

Signature:

```shell
@@ -56,8 +56,6 @@ wait_for_url http://127.0.0.1:5984 5 3

Wait for a particular PID to exit. Wait `$duration` seconds between attempts, try `$iterations` times. Defaults to `1` seconds and `3` times.

Requires `bash`.

Signature:

```shell


+ 2
- 2
wait_for_pid_exit.sh View File

@@ -14,12 +14,12 @@ wait_for_pid_exit () {
debug_inline "waiting for $pid to exit "
until ( ! ps ax | grep $pid | grep -v grep > /dev/null); do
if [ $waiting -eq $iterations ]; then
let after=$duration*iterations
after=`expr $duration \* $iterations`
debug_inline "failed, $pid still running after $after seconds\n"
return 1
fi
debug_inline .
let waiting=waiting+1
waiting=`expr $waiting + 1`
sleep $duration
done
debug_inline " succeeded\n"


+ 2
- 2
wait_for_url.sh View File

@@ -17,12 +17,12 @@ wait_for_url () {
debug_inline "waiting for $url "
until ($cmd); do
if [ $waiting -eq $iterations ]; then
let after=$duration*iterations
after=`expr $duration \* $iterations`
debug_inline "failed, $url can not be reached after $after seconds\n"
return 1
fi
debug_inline .
let waiting=waiting+1
waiting=`expr $waiting + 1`
sleep $duration
done
debug_inline " succeeded\n"


Loading…
Cancel
Save