See my own comment below:<br><br><div class="gmail_quote">On Thu, Jul 25, 2013 at 11:46 AM, Lisa Kachold <span dir="ltr"><<a href="mailto:lisakachold@obnosis.com" target="_blank">lisakachold@obnosis.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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 </b></div></div></div></div></blockquote>
<div><br></div><div> Would this work to append to the line:</div><div><br></div><div><pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:14px;vertical-align:baseline;background-color:rgb(238,238,238);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;line-height:18px">
<code style="margin:0px;padding:0px;border:0px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif">sed -e 's/unique/ $username/' /etc/samba/smb.conf</code></pre>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>

<div><b>     </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>
<span class="HOEnZb"><font color="#888888">

-- <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>
</font></span></div>
</div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div><br></div>(503) 754-4452 Android<br>(623) 239-3392 Skype<br>(623) 688-3392 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>