LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-22-2009, 04:41 PM   #1
Plato
LQ Newbie
 
Registered: Jun 2009
Location: Huntsville, Alabama
Distribution: RHEL 5.3
Posts: 12

Rep: Reputation: 0
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.
 
Old 07-22-2009, 04:59 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
sed '/valid users/ s/$/, newuser/' smb.conf
 
Old 07-22-2009, 05:19 PM   #3
Plato
LQ Newbie
 
Registered: Jun 2009
Location: Huntsville, Alabama
Distribution: RHEL 5.3
Posts: 12

Original Poster
Rep: Reputation: 0
#!/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?

Last edited by Plato; 07-22-2009 at 05:43 PM.
 
Old 07-22-2009, 06:39 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Use double-quotes if you want to expand the variable name

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script to create text in a file or replace value of text if already exists knightto Linux - Newbie 5 09-11-2008 12:13 AM
what is the command to add text into a text file? newbiebash Programming 2 09-08-2008 09:07 AM
bash: how to insert information into the middle of text file craftereric Linux - Newbie 2 06-12-2008 04:19 PM
simple php script to add line/file to text file dnoy Programming 1 05-21-2008 06:08 PM
How to add a text to first line of a text file? oskeewow Linux - Newbie 6 04-23-2008 01:40 PM


All times are GMT -5. The time now is 10:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration