Hi, I am writing a script that will add a user to my server that includes a system user, samba user, shared samba and nfs home folder, access to a public folder and possibly an rsa key for my vpn. Anyway everything was going fine until I needed to add the Samba user and I can't for the life of me figure out how to use stdin to give the smbpasswd program the password that is/will be defined by a read input from the user, meant to be used for both the system id and the samba id. I like to divide my scripts into small functions to be added to a main routine later on so here is my function:
Code:
# Add user and password to Samba
function samba_add
{
(echo $pass; echo $pass) | smbpasswd -s -a $user
}
and this is the output it gives me from bash -x
Code:
+ read user
user
+ read pass
password
+ echo password
+ echo password
+ smbpasswd -s -a user
Failed to add entry for user user.
and if I only have one instance of the password, ie:
Code:
# Add user and password to Samba
function samba_add
{
(echo $pass) | smbpasswd -s -a $user
}
i get
Code:
+ read user
user
+ read pass
password
+ echo password
+ smbpasswd -s -a user
Mismatch - password unchanged.
Unable to get new password.
so it seems to me that it is taking the password, based on the results I get from the script using only one instance of the password variable because it gives a mismatch error. Meaning the password entered is not a match with nothing/empty. So how do I send the contents of the password variable to the initial prompt for the smbpasswd and the verification prompt?
Bookmarks