TIL: timeout in Bash scripts
a year ago
- #Bash
- #Scripting
- #DevOps
- Bash scripts can use the `timeout` utility to limit the execution time of commands.
- The `until` loop in Bash checks for a condition (e.g., server health) but can loop indefinitely if the condition is never met.
- `timeout` sends a signal (default `SIGTERM`) to terminate a command if it exceeds the specified time limit.
- `timeout` cannot be used directly with shell built-ins like `until` because they are not killable processes.
- A workaround is to wrap the `until` loop in a separate Bash process or script, allowing `timeout` to manage it effectively.