views:

896

answers:

8

How can I pipe the new password to smbpasswd so I can automate my installation process.

A: 

using either pipelines or redirection.

icco
+1  A: 

Try something like this:

(echo oldpasswd; echo newpasswd) | smbpasswd -s
Mark Harrison
A: 

@mark I am getting this:

Mismatch - password unchanged.
Unable to get new password.
Unkwntech
+2  A: 

Thanks to Mark I found the answer:

(echo newpassword; echo confirmNewPassword) | smbpasswd -s

BTW: (echo oldpasswd; echo newpasswd) | smbpasswd -s does not work.

Unkwntech
A: 

@unk

what happens when you run

smbpasswd -s

by itself, and you type in from the keyboard?

Mark Harrison
+1  A: 

I use the following in one of my scripts:

   echo -ne "$PASS\n$PASS\n" | smbpasswd -a -s $LOGIN

With echo:

-e : escape sequences, like \n

-n : don't add implicit newline at end

With smbpasswd:

-a : add new user

-s : silent

Bruno De Fraine
A: 

" echo -ne "$PASS\n$PASS\n" | smbpasswd -a -s $LOGIN "

Thanks for this suggestion, it's works fine in my script! Jvonne

Jvonne Rampoldi
A: 

Hi, can anyone suggest me a command to add samba user? I want add samba user through php in one single command by avoiding password prompt. " echo -ne "$PASS\n$PASS\n" | smbpasswd -a -s $LOGIN " this command says "Failed to modified password entry for user $username" because im trying to add a user. Can anyone help me? Thanks.

shereen
This should be it's own question, but likely the user that is executing PHP (Apache) does not have the correct privilege to add/edit users.
Unkwntech