Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto answering multiple prompts of a bash command in (Bash/Docker RUN) non interactively

Tags:

There are ways to automatically answer -y in bash commands for example like

RUN apt-get install -y nodejs

but I'm having this case I want to run

 dpkg --install someDebianpackage.deb && apt install --assume-yes --fix-broken

It actually answers y for the immediate prompt given by it but in the later stage it asks me to configure geographic are with answer 6

enter image description here

and after that again I want to answer the command with 20 for the city corresponding to timezone

enter image description here

and then again with answer 31 and then 1 as same as above for different questions.

What I want to know is to run this command as single command in a non-interactive way. ( I'm hoping to make a docker file and put the above command along with some other commands that can be chained with && in a RUN Command for example like

RUN apt-get update && apt-get install sudo && "the above command along with their answers" && "some other command"

I would highly appreciate some guidance over this

like image 529
Charith Jayasanka Avatar asked Aug 05 '20 20:08

Charith Jayasanka


1 Answers

Technically, you can auto-answer prompts with a tool like expect. However, that's usually much more difficult than getting the program to stop asking you questions.

I'm not sure why apt is asking for your timezone, but I suspect that you're pulling in the tzdata package somehow, which wants to configure your timezone. To avoid these questions, you should set the frontend to non-interactive:

To run dpkg (behind other tools like Apt) without interactive dialogue, you can set one environment variable as

DEBIAN_FRONTEND=noninteractive

(Source.)

In a Dockerfile, you can set an environment variable like this:

ENV DEBIAN_FRONTEND=noninteractive
like image 156
Nick ODell Avatar answered Oct 05 '22 18:10

Nick ODell