LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   script to add text in middle of file (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-add-text-in-middle-of-file-742050/)

Plato 07-22-2009 03:41 PM

script to add text in middle of file
 
I'm looking for a solution to adding text to the middle of the smb.conf file. This is my script so far.

Code:

#!/bin/sh
echo "Enter username"
read NAME
useradd -c "$NAME" -m $NAME
echo $NAME = $NAME >> /etc/samba/smbusers
smbpasswd -a $NAME

What I need it to do now is the user that is created be added to a share as a valid user inside the same script. i.e.

smb.conf file share...

[file]
valid users = blahblah, blahblah2, blahblah3, (Add New User Here)
path = /file
create mask = 0755
browesable = no
read only = no

Thanks in advance.

Tinkster 07-22-2009 03:59 PM

sed '/valid users/ s/$/, newuser/' smb.conf

Plato 07-22-2009 04:19 PM

#!/bin/sh
echo "Enter username"
read NAME
useradd -c "$NAME" -m $NAME
mkdir /file/$NAME
echo $NAME = $NAME >> /etc/samba/smbusers
smbpasswd -a $NAME
sed '/valid users/ s/$/, $NAME/' /etc/samba/smb.conf

...is the new code.

It makes $NAME a valid user of the new directory made. /file is the root directory, and has its own share, is there an easy fix to making $NAME a valid user of /file which is already made?

Tinkster 07-22-2009 05:39 PM

Use double-quotes if you want to expand the variable name

Code:

sed -i "/valid users/ s/$/, $NAME/" /etc/samba/smb.conf


All times are GMT -5. The time now is 07:24 PM.