Answer the question
In order to leave comments, you need to log in
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
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.
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
$
command <<EOF
yes
EOF
echo yes > answers.txt
command <answers.txt
Not exactly pure bash, but lets you do without those bikes:
ansible
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 questionAsk a Question
731 491 924 answers to any question