Torrius
Torrius

Reputation: 787

Automatic answer to interactive shell prompt (yes/no)

I run a bash script. After some minutes execution it prompts me enter 'Y' or 'N' to continue. Some minutes later it can prompt me again some times.

Is it possible to answer its questions automatically in common if I know the count and sequence of right answers (e.g. Y, N, N, N)

Upvotes: 1

Views: 4832

Answers (2)

Rasim
Rasim

Reputation: 1296

The Expect tool used in cases like this. It is useful for automating interaction with CLI applications (Expect on Wikipedia).

Upvotes: 1

jim mcnamara
jim mcnamara

Reputation: 16379

Try a here document:

bashscript.shl [options] <<-END
Y
Y
Y
N
END

Put any kind of answer you want, passwords, etc. Will NOT work for ssh or sftp.

Upvotes: 3

Related Questions