How to populate the command line interface?

I have to automate the installation phase of an outdated system because I don’t want to put in more effort again and again when I want to install it. During the installation process on a Linux terminal, I have to answer some questions regarding basic configurations. In fact, it is easy to automate shell commands by placing them in a batch file as follows:

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

However, I do not know how to automate answers to specific questions, such as:

Enter the server 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 that can handle this situation? or is there a way to pass responses as parameters in a batch file?

Thanks in advance.

+4
source share
2 answers

Linux - expect.

expect , . expect , .

:

#!/usr/bin/expect -f
spawn someScript.sh
expect "Enter the server IP address:"
send "10.0.0.4\r"
expect "Enter the email of the contact person:"
send "foo@bar.com\r"
expect "Would you like to disable UDP services?(y/n) [n]:"
send "y\r"
+3

, , script:

#!/bin/bash
read -p "Enter something:" thing
read -p "Enter server IP:" ip
read -p "Enter Email:" email
echo Received $thing, $ip, $email

answers

thingywhatnot
11.12.33.240
bozo@brains.com

installationScript < answers

Received thingywhatnot, 11.12.33.240, bozo@brains.com
+1

All Articles