0

I've wrote function in node,js as follows:

const addUserToSamba = (userLogin, password) => {

         const echoPassword = spawnSync('echo', ['ne',`${password}\n${password}\n`]);

         const addUserCredentialsToSamba = spawnSync('smbpasswd', ['-a', '-s', userLogin], {
                 input: echoPassword.stdout,
         });

         console.log('Added user credentials to Samba configuration');
         console.log(addUserCredentialsToSamba.stderr.toString());
         console.log(addUserCredentialsToSamba.stdout.toString());
}

I want to achieve something like this in bash:

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

When I'm running addUserToSamba(userLogin, password); function with given userlLogin and user password then I even get message Added user ${userLogin} as a stdout of the addUserCredentialsToSamba outcome.

But the credentials don't work.

Have I correctly rewritten this bash function to the node.js one? If no, how can I fix it?

1 Answer 1

1

You can simply skip the echo part and output the credentials directly to the smbpasswd process:

const addUserCredentialsToSamba = spawnSync('smbpasswd', ['-a', '-s', userLogin], {
    input: `${password}\n${password}\n`,
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.