S
S
Shimpanze2019-10-19 12:28:44
linux
Shimpanze, 2019-10-19 12:28:44

How can the Linux shell automatically answer a couple of questions?

When creating a user:
$ adduser customuser
you need to answer a few questions:

Enter new UNIX password:
Retype new UNIX password:
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]

How to answer them automatically?
Why doesn't this design work?
printf "0000\r
0000\r
\r
\r
\r
\r
\r
y\r" | adduser customuser

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vladimir, 2019-10-19
@Casufi

Why not use another command and specify all the parameters from the beginning in the line?
https://www.opennet.ru/man.shtml?topic=useradd&cat...

V
Vladimir Bobylev, 2019-10-24
@ShturmN

pwgen 14 1 -B > /tmp/ps ; usermod -p $(mkpasswd -m sha-512 `cat /tmp/ps | tr -d '\r' | tr -d '\n'`) <username> ; cat /tmp/ps | mail -s "ВНИМАНИЕ! ВАШ ПАРОЛЬ!" кому@куда.ru ; rm /tmp/ps

Generate and send by email.
The rest is through expect.

R
Ruslan Fedoseev, 2019-10-19
@martin74ua

man expect

L
Lynn "Coffee Man", 2019-10-19
@Lynn

Linux does not have cmd. There are all kinds of shells (shell), the most popular are bash, zsh, etc.
However, the question should still not be about them, but about the adduser command and you need to read the help for this command: man adduser

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question