I would like to set a password for setting up samba share directory using a shell script. I wrote the following script test.sh:
#!/bin/bash
pass=123456
(echo "$pass"; echo "$pass") | smbpasswd -s -a $(whoami)
This prints the following:
When run by root:
smbpasswd [options] [username]
otherwise:
smbpasswd [options]
options:
-L local mode (must be first option)
-h print this usage message
-s use stdin for password prompt
-c smb.conf file Use the given path to the smb.conf file
-D LEVEL debug level
-r MACHINE remote machine
-U USER remote username
extra options when run by root or in local mode:
-a add user
-d disable user
-e enable user
-i interdomain trust account
-m machine trust account
-n set no password
-W use stdin ldap admin password
-w PASSWORD ldap admin password
-x delete user
-R ORDER name resolve order
As it points out, I was not running it as root, when I run it as root, i.e., sudo ./test.sh, it runs fine. But the catch is, it adds root instead of noobuser, which is my logged in user.
How can I add noobuser by doing something similar (I have a feeling I'm missing something here)?
$(whoami)by$(echo noobuser)?