Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill in a Command Line Interface?

I am to automate the installation phase of a legacy system, because I do not want to put more efforts again and again when ever I want to install it. During the installation process on Linux Terminal, I have to answer some questions regarding the basic configurations. Indeed, it is easy to automate the shell commands by putting them all in a batch file like the following:

bin/startServer destination/sub_v1
bin/startAdminInterface
....

However, I do not know how to automate the answers of a specific questions like the following:

Enter the server's IP address: 
Enter the email of the contact person:
Would you like to disable UDP services?(y/n) [n]:
....

Is there any tool or programming language can deal with this situation? or Is there any way to pass the answers as a parameters within the batch file?

Thanks in advance.

like image 849
Kh.Taheri Avatar asked Jun 09 '15 10:06

Kh.Taheri


People also ask

How do you use a command line interface?

Through the CLI, users interact with a system or application by typing in text (commands). The command is typed on a specific line following a visual prompt from the computer. The system responds to the text, and the user may then type on the next command line that appears.

What can you do with CLI?

A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage computer files and interact with the computer. Command-line interfaces are also called command-line user interfaces, console user interfaces and character user interfaces.

Is CMD command line interface?

The Command Prompt, officially called the Windows Command Processor and often abbreviated to CMD, is the command line interface for Windows operating systems. A command line interface is a way of interacting with a computer directly using text commands.


1 Answers

The classic Linux tool for this job is expect.

With expect one can expect different questions and variations on a question, and the question does not have to be typed exactly. expect does not blindly answer every prompt, but rather it provides answers to the questions actually asked.

Here is a short example:

#!/usr/bin/expect -f
spawn someScript.sh
expect "Enter the server's IP address:"
send "10.0.0.4\r"
expect "Enter the email of the contact person:"
send "[email protected]\r"
expect "Would you like to disable UDP services?(y/n) [n]:"
send "y\r"
like image 85
dotancohen Avatar answered Oct 18 '22 09:10

dotancohen