Reputation: 1
We have a startup script for an application (Owned and developed by different team but deployments are managed by us), which will prompt Y/N to confirm starting post deployment. But the number of times it will prompt will vary, depends on changes in the release.
So the number of times it will prompt would vary from 1 to N (Might be even 100 or more than that).
We have automated the deployment and startup using Jenkins shell script jobs. But startup prompts number is hardcoded to 20 which might be more at sometime.
Could anyone please advise how number of prompts can be handled dynamically. We need to pass Y whenever there is pattern in the output "Do you really want to start".
Checked few options like expect, read. But not able to come up with a solution.
Thanks in advance!
Upvotes: 0
Views: 147
Reputation: 76409
In general, the best way to handle this is by (a) using a standard process management system, such as your distro's preferred init system; or, if that's not possible, (b) to adjust the script to run noninteractively (e.g., with a --yes
or --noninteractive
option).
Barring that, assuming your script reads from standard input and not the TTY, you can use the standard program yes
and pipe it into the command you're running, like so:
$ yes | ./deploy
yes
prints y
(or its argument) over and over until it's killed, usually by SIGPIPE.
If your process is reading from /dev/tty
instead of standard input, and you really can't convince the other team to come to their senses and add an appropriate option, you'll need to use expect
for this.
Upvotes: 1