D
D
dmg88112017-09-01 07:01:36
linux
dmg8811, 2017-09-01 07:01:36

Is it possible to create a completely self-contained bash script that does not require manual typing?

Is it always possible to create a bash script to run without input at all?
That is, I want to create such a new_os_init.sh, so that it installs everything I need, creates a user, a group, configures visudo .... in short, everything that I am currently doing manually on a new server.
Is this always possible or at least sometimes, but you still need to enter something with your hands?
If always, then in which direction to dig: how to make him 1) answer yes 2) choose the answer option that I need, etc.
Of course, I know in advance what to answer where.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
AVKor, 2017-09-01
@AVKor

Can.

X
xotkot, 2017-09-01
@xotkot

Most linux utilities can work in "script" mode (eg parted -s ... ), that is, automatically accept a given response or default action (eg rm -f ... delete without confirmation).
In extreme cases, you can find utilities that can do this. For example, to set a password after creating a user, instead of passwd , you can use chpasswd : If the utility does not support script mode and there are no suitable replacements, then you can use the expect utility , which Konstantin wrote about earlier.

S
Saboteur, 2017-09-01
@saboteur_kiev

Can.
The simplest option is to read the help about command line arguments, many commands can be given all the necessary data at startup.
Read more about redirects. For example, for a command like

$ command
press "yes" to continue
(вводим yes)
completed
$

In an automation script, you can do
command <<EOF
yes
EOF

echo yes > answers.txt
command <answers.txt

V
Vladimir Kuts, 2017-09-01
@fox_12

Not exactly pure bash, but lets you do without those bikes:
ansible

K
Konstantin ™, 2017-09-01
@Energoblock

You can :)
To interact with interactive requests, there is a program expect.
Very detailed with examples of expect is described on Habré .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question