tags:

views:

222

answers:

4

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?

+1  A: 

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.

Daniel
For the benefit of the author of th question, this is called a 'Here Document', in case you want to look it up.
IRBMe
+1  A: 

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.

dfa
I should have recalled that. I have used except for this precise reasons tons of time.
Daniel
A: 

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
IRBMe
A: 

Googling for "script useradd" provides many promising results. : ]

tex
I am appreciate your lmgtfy comment. I was more looking for <<EOF that Daniel posted. I had a couple of issues where I would lose "focus" and the script would terminate.
tathamr