dkb
dkb

Reputation: 4596

How to handle user prompt/user intervention during shell script execution

Consider shell scripts which ask user's input to proceed or not[yY/nN] and another script calls all these scripts.
I don't want to give Yy input manually.
Note: User input is not an argument to a script and it occurs anytime during script execution.
Consider 3 shell scripts viz: a.sh, b.sh, c.sh.
On execution, scripts prompt:

"You want to Proceed[Y/y/N/n]?"

Now, Wrapper.sh calls a.sh, b.sh, c.sh and also provides Y/y or N/n input as and when those scripts prompts.
I can not pass an argument as a.sh "Y"
[ps: a.sh b.sh c.sh are not executable and non-editable]
Can not install any third party plugins on RHEL, So need to use only default plugins/commands.

Upvotes: 0

Views: 275

Answers (2)

dsumsky
dsumsky

Reputation: 377

You can try expect tool which is used to feed input automatically to an interactive program. Try to begin with something like this:

#!/usr/bin/expect

set timeout 10

spawn "PATH_TO/a.sh"
expect "You want to Proceed" 
send "y\r"

interact

Upvotes: 2

raymondboswel
raymondboswel

Reputation: 591

I haven't used this myself, but take a look at 'expect'. This exactly what it's there for. Good luck!

Upvotes: 0

Related Questions