XanderLynn
XanderLynn

Reputation: 883

bash script shell input

I am currently writing a bash script and when i run the useradd command it requires 2x input. What is the command to input from the bash script into the prompted password fields from useradd?

Upvotes: 1

Views: 781

Answers (3)

Daniel C. Sobral
Daniel C. Sobral

Reputation: 297265

If the input is being read from stdin, you could do this;

useradd <<EOF
first input
second input
EOF

Some programs, however, do not read from stdin precisely to stop this kind of thing.

Edit

As remarked upon, this is called a "HERE document", in case you want to look it up.

Upvotes: 1

IRBMe
IRBMe

Reputation: 4425

I can't be bothered booting up my Linux system to check, but does the useradd program still prompt if you pass the information on the command line?

useradd -m -p encryptedPassword username

Upvotes: 0

dfa
dfa

Reputation: 116412

try using expect:

Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc

expect works also for programs that do not read from stdin.

Upvotes: 1

Related Questions