function::qs_wait - Linux


qs_wait is a command-line tool designed for automating the execution of scripts or commands. It allows users to suspend script execution for a specified time interval or until a certain condition is met. This makes it ideal for controlled execution of tasks, especially in scenarios involving timed events, network operations, or resource monitoring.


qs_wait [options] <duration> [condition]


  • -i, –interval : Specifies the interval (in seconds) at which the condition should be checked. Default: 1 second
  • -m, –max-retries : Sets the maximum number of times the condition should be checked before exiting. Default: 10
  • -t, –timeout : Sets the maximum wait time (in seconds) before exiting. Default: 30 seconds
  • -s, –sleep : Specifies the sleep time (in seconds) between each condition check. Default: 0 seconds
  • -p, –pause : Pauses script execution without checking for any condition.


# Wait for 30 seconds
qs_wait 30

# Wait until the file exists
qs_wait -c "test -f /path/to/file.txt"

# Wait for 5 minutes, pausing between checks
qs_wait -t 300 -p -s 10

# Wait for 60 seconds, checking every 5 seconds, with a maximum of 5 retries
qs_wait -t 60 -i 5 -m 5

Common Issues

  • Condition not met: Check the condition syntax or ensure that the file/service it checks exists or is accessible.
  • Excessive wait time: Adjust the timeout (-t) option to a more suitable value.
  • Script execution stops without waiting: Verify the condition syntax and ensure it evaluates to true when the desired wait period has elapsed.


qs_wait can be integrated into scripts or command chains using the wait construct. For instance, the following script uses qs_wait to execute a command only if a certain file is created:


# Wait for the file to be created
qs_wait -c "test -f /path/to/file.txt"

# Execute the command

Related Commands

  • sleep: Suspends script execution for a specified duration.
  • date: Provides the current date and time, useful for setting wait intervals.
  • bash: Provides the wait construct for integrating qs_wait into scripts.