qDup sh commands have a watch list of commands that are invoked with each new line of output from the sh command.
watch usually contains regex commands to match patterns in the output.
- sh: ./doSomething.sh
watch:
- regex: ERROR
then:
- ...The doSomething.sh script is still running in the ssh connection while the watch commands are executing, therefore we cannot run commands that would need control of the ssh connection. The following commands cannot be used in watch:
-
sh- cannot write to the ssh connection while anothershis running -
wait-for- cannot pause the script if anshcommand is running -
repeat-until- cannot block otherwatchcommands -
script- script can only be used ifasync: trueis used to spawn a new ssh connection.
- sh: ./doSomething.sh
watch:
- regex: ERROR
then:
- script: in-case-of-errorIf you want to run some of the above commands in parallel to doSomething.sh then we recommend creating a second script and starting that script before doSomething.sh and sending a signal when doSomething.sh finishes.
scripts:
alsoDoThis:
- sh: ./this.sh
- repeat-until: doSomething-done
then:
- sh: ...
doSomething:
- script:
name: alsoDoThis
async: true
- sh: doSomething.sh
- signal: doSomething-doneThe watch section is best used for actions that cannot wait for the sh command to finish.
This includes:
-
interrupting commands that will not end using
ctrlC
- sh: tail -f /var/log/messages
watch:
- regex: FOO
then:
- ctrlC
timer:
10m: #max wait time
- ctlrC--
signaling other scripts when conditions are ready
- sh: doSomething.sh
watch:
- regex: ready
then:
- signal: something_ready-
starting other scripts when conditions are ready
- sh: doSomething.sh
watch:
- regex: ERROR
then:
- script:
name: collect-error-data
async: trueNote: some performance tests are sensitive to the overhead of establishing a new ssh connection. Use the signaling method to have the script start with a wait-for and only continue if signaled.
Some sh commands require interaction. For example using subscription-manager asks for a password. There are two ways interact with a command.
The first option is using the watch context with a regex and the send-text command.
- sh: subscription-manager register --username=me@domain.com
watch:
- regex: "Password: "
then:
- send-text: "paSSw0rd"The 'watch' method works if the command output (e.g. subscription-manager) is a complete line but subscription-manager prompts for the password and does not send a newline after Password: so the watch will not run. If the command does not send a newline after the patter then we have to use the prompt option.