I am trying to append a variable from an adduser script to a line in a config file (for samba).<div><br></div><div><div>Can someone assist me here?</div><div><br></div><div>The function is in BOLD below: <b>createNewSambaAllow()</b></div>
<div><b><br></b></div><div>It's not working to put the new line in the smb.conf file? </div>
<div><br></div><div>Cry! Beg! Plead!</div><div><br></div><div><div><br></div><div>Note: This is a assuming I already have a user named "unique" in my smb.conf line.</div>
<div><br></div><div>#####################################start script#######################################3</div><div><div>#!/bin/bash</div><div><br></div><div><div># Add shell and samba user.</div><div><br></div><div>
_now=$(date +"%m_%d_%Y")</div>
<div>basedir=/home</div><div>usershell=/bin/bash</div><div><br></div><div>## Declare all the functions first</div><div><br></div><div>## function to check if user already exists on system</div><div>ifUserExits(){</div><div>
grep $1 /etc/passwd > /dev/null</div><div> [ $? -eq 0 ] && return $TRUE || return $FALSE</div><div>}</div><div><br></div><div>## function to create the user with default shell and home directory passed from below</div>
<div>createNewUser(){</div><div> if /usr/sbin/useradd "$@"</div><div> then echo "User $6 Added"</div><div> fi</div><div>}</div><div><br></div><div>## function to set the user password</div>
<div>createPassword(){</div><div> if echo -e "$1\n$1\n" | echo $1:$2 |chpasswd</div><div> then echo "Password Created for User $2"</div><div> fi</div><div>}</div><div><br></div><div>
## function to setup samba user</div><div>createNewSambaUser(){</div><div> if (echo $1; echo $1) | /usr/bin/smbpasswd -as $2</div><div> then echo "Samba Account for User $2 Added"</div><div> fi</div>
<div>}</div></div><div><br></div>
<div><b>#####This is the part I have issues with:</b></div><div><b><br></b></div><div><b>## function to add user to the Samba config and restart daemon</b></div><div><b>createNewSambaAllow(){</b></div><div><b> # Copy to backup the config:</b></div>
<div><b>
cp /etc/samba/smb.conf /etc/samba/smb.conf-$_now</b></div><div><b> # stuff the line we need to append to into a variable called $oldline</b></div><div><b> # this is supposed to look like this "valid users = unique thing1 thing2 thing3 alice"</b></div>
<div><b> oldline = grep unique /etc/samba/smb.conf</b></div><div><b> # delete the old line in the smb.conf</b></div><div><b> sed '/unique/d' /etc/samba/smb.conf >>/etc/samba/smb.conf</b></div>
<div><b> # dump the old line and the new user into the bottom of smb.conf</b></div>
<div><b> echo $oldline && echo $username >> /etc/samba/smb.conf</b></div><div><b> # restart samba</b></div><div><b> /etc/init.d/samba restart</b></div><div><b> echo "Samba Config Added and Daemon restarted"</b></div>
<div><b>}</b></div><div><br>
</div><div>### This is just for your info #####</div><div><br></div><div>## make sure root is running script</div><div>if [ $(id -u) -ne 0 ]</div><div>
then</div><div> echo "You must be root or use sudo to run this script!"</div><div> exit 2</div><div>fi</div><div><br></div><div>## get username from input</div><div>read -p "Enter username : " username</div>
<div><br></div><div>## if user doesn't exist, add user</div><div>if ( ! ifUserExits $username )</div><div><br></div><div>then</div><div> ## get password from input</div><div> read -p "Enter password : " password</div>
<div> createNewUser -m -b $basedir -s $usershell $username</div><div> createPassword $password $username</div><div> createNewSambaUser $password $username</div><div> createNewSambaAllow $username</div>
<div>else</div><div> ## oops, username already being used</div><div> echo "Username \"$username\" already exists"</div><div> exit 3</div><div>fi</div><div><br></div><div># End Bash Example</div>
-- <br><div><br>
</div><div>Anyone?</div><div><br></div><div><br></div>
<a href="tel:%28503%29%20754-4452" value="+15037544452" target="_blank">(503) 754-4452</a> Android<br><a href="tel:%28623%29%20239-3392" value="+16232393392" target="_blank">(623) 239-3392</a> Skype<br><a href="tel:%28623%29%20688-3392" value="+16236883392" target="_blank">(623) 688-3392</a> Google Voice<br>
**<br><a href="http://it-clowns.com/c/" target="_blank">it-clowns.com</a><br>Chief Clown<br><br><br><br><br><br><br><br><br><br><br><br><br>
<br>
</div></div>
</div>