<p>How can I pipe the new password to smbpasswd so I can automate my installation process.</p>

[{'answer_id': 12016, 'author': 'icco', 'author_id': 1063, 'author_profile': 'https://Stackoverflow.com/users/1063', 'pm_score': -1, 'selected': False, 'text': '<p>using either <a href="http://en.wikipedia.org/wiki/Pipeline_(Unix)" rel="nofollow noreferrer">pipelines</a> or <a href="http://en.wikipedia.org/wiki/Redirection_(Unix)" rel="nofollow noreferrer">redirection</a>.</p>\n'}, {'answer_id': 12026, 'author': 'Mark Harrison', 'author_id': 116, 'author_profile': 'https://Stackoverflow.com/users/116', 'pm_score': 4, 'selected': False, 'text': '<p>Try something like this:</p>\n\n<pre><code>(echo oldpasswd; echo newpasswd) | smbpasswd -s\n</code></pre>\n'}, {'answer_id': 12032, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 7, 'selected': True, 'text': '<p>Thanks to Mark I found the answer:</p>\n\n<pre><code>(echo newpassword; echo confirmNewPassword) | smbpasswd -s\n</code></pre>\n\n<p>BTW: (echo oldpasswd; echo newpasswd) | smbpasswd -s  does not work.</p>\n'}, {'answer_id': 62796, 'author': 'Bruno De Fraine', 'author_id': 6918, 'author_profile': 'https://Stackoverflow.com/users/6918', 'pm_score': 5, 'selected': False, 'text': '<p>I use the following in one of my scripts: </p>\n\n<pre><code>   echo -ne "$PASS\\n$PASS\\n" | smbpasswd -a -s $LOGIN\n</code></pre>\n\n<p>With echo:</p>\n\n<p>-e : escape sequences, like \\n</p>\n\n<p>-n : don\'t add implicit newline at end</p>\n\n<p>With smbpasswd:</p>\n\n<p>-a : add new user</p>\n\n<p>-s : silent</p>\n'}, {'answer_id': 15841153, 'author': 'Charles Prince', 'author_id': 2001428, 'author_profile': 'https://Stackoverflow.com/users/2001428', 'pm_score': 1, 'selected': False, 'text': "<p>This unfortunately is not desirable for two reasons:\n1) if the user uses a combination of '\\n' in the password there will be a mismatch in the input\n2) if there are unix users on the system, then a user using the utility ps may see the password</p>\n\n<p>A better way would be to put the names in a file and read from the file and use python pexpect to read them, not like below, but the simple script is enough to see how to use pexpect</p>\n\n<pre><code>#!/usr/bin/python\n#converted from: http://pexpect.sourceforge.net/pexpect.html\n#child = pexpect.spawn('scp foo myname@host.example.com:.')\n#child.expect ('Password:')\n#child.sendline (mypassword)\nimport pexpect\nimport sys\nuser=sys.argv[1]\npasswd=sys.argv[2]\nchild = pexpect.spawn('/usr/bin/smbpasswd -a '+str(user))\nchild.expect('New SMB password:')\nchild.sendline (passwd)\nchild.expect ('Retype new SMB password:')\nchild.sendline (passwd)\n</code></pre>\n\n<p>then try: ./smbpasswd.py userName1 'f#@(&amp;*(_\\n895'</p>\n"}, {'answer_id': 19770281, 'author': 'ReklatsMasters', 'author_id': 1556249, 'author_profile': 'https://Stackoverflow.com/users/1556249', 'pm_score': 3, 'selected': False, 'text': "<p>Use this\n<code>echo 'somepassword' | tee - | smbpasswd -s</code></p>\n"}, {'answer_id': 53428249, 'author': 'Samuli Seppänen', 'author_id': 2543558, 'author_profile': 'https://Stackoverflow.com/users/2543558', 'pm_score': 2, 'selected': False, 'text': '<p>I had to create a new Samba user in a Puppet 5.x Exec resource and for various reasons none of the above worked. Fortunately this rather silly-looking command worked:</p>\n\n<pre><code>yes vagrant|head -n 2|smbpasswd -a -s vagrant\n</code></pre>\n\n<p>Password here is of course "vagrant".</p>\n'}]
['https://Stackoverflow.com/questions/12009', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/115/']