LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 08-05-2009, 02:19 PM   #1
Plato
LQ Newbie
 
Registered: Jun 2009
Location: Huntsville, Alabama
Distribution: RHEL 5.3
Posts: 12

Rep: Reputation: 0
File Copying to Same File


Having a problem trying to make a command that will copy part of a file to another part of a file. smb.conf file is the file that is being edited. Appending an already creating valid users list, to another share with the same valid users. The reason for this is so whenever new users are added with another script, they are appended to Share1, this will be updating the new share with newly created users on Share1. Will i need to use awk or sed?

i.e.
[Share1]
valid users = user1, user2, user3, user4, user5, user6, user 7

[Share2]
valid users = (add all Share1 valid users here)

Many thanks in advance
 
Old 08-05-2009, 05:08 PM   #2
synss
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian, Gentoo, Mac OS X
Posts: 137

Rep: Reputation: 22
I do not understand what you are trying to do.

If you want to append to a file, use redirection >>.
If you want to write to different files with a single command, use tee(1).
If you want to append something at the end of a specific line in a file, use sed(1), see, e.g., http://www.linuxquestions.org/questi...e-done-684650/
 
Old 08-05-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
Sorry for not making much sense in my post.

Basically what I want is to have Share1's Valid Users be appended to Share2's when the share is created. Currently, I have a script that will attach new users to Share1. When I make a new share, with another script, I want the all the users for Share1, to be added to Share2.

p.s. Share2 isn't created yet, but when it is, I'd like to have all Share1's users be added to it.
 
Old 08-05-2009, 05:26 PM   #4
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 542

Rep: Reputation: 33
couldn't you simply copy Share1 to Share2 right after creating share2? If there is a chance there is already a member in share2 I would use the append such as:
cat share1 >> share2
This will add share1 to the end of share2
 
Old 08-05-2009, 05:46 PM   #5
Plato
LQ Newbie
 
Registered: Jun 2009
Location: Huntsville, Alabama
Distribution: RHEL 5.3
Posts: 12

Original Poster
Rep: Reputation: 0
DotHQ, let me explain the situation a bit further..

The problem is that there won't be a user to maintain the system / smb.conf file, so I'm writing scripts that will make new shares and add existing users. There will be someone who can log into terminal and run scripts, but nothing more than that.

I have a script that adds users to samba, and then add them to a root share (directory), which then has many other files inside of it, which are all shares themselves for speecific users and have specific permissions for each.

Since there will be new users being added, i'd like to copy the valid users from Share1 (since it will have every user there is on the system), to the new Share2. A simple (not for me lol), cp from Share1's Valid users to be mimiced to Share2's Valid users.

I'm not even sure if I just made sense..
 
Old 08-05-2009, 08:55 PM   #6
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 333

Rep: Reputation: 141Reputation: 141
This uses GNU sed.
It replaces every subsequent 'valid users =' line with the first one.
Code:
sed '/^[[:blank:]]*valid users =/{
h
:a n; /^[[:blank:]]*valid users =/g; ba
}' infile > outfile

# Input
[Share1]
valid users = user1, user2, user3, user4, user5, user6, user 7

[Share2] 
valid users = <Anything here will be overwritten>

[Share3] 
valid users = <Anything here will be overwritten>

# Output
[Share1]
valid users = user1, user2, user3, user4, user5, user6, user 7

[Share2]
valid users = user1, user2, user3, user4, user5, user6, user 7

[Share3]
valid users = user1, user2, user3, user4, user5, user6, user 7

Last edited by Kenhelm; 08-05-2009 at 10:28 PM. Reason: Replaced ^ with ^[[:blank:]]* in case the line is indented.
 
Old 08-06-2009, 11:04 AM   #7
Plato
LQ Newbie
 
Registered: Jun 2009
Location: Huntsville, Alabama
Distribution: RHEL 5.3
Posts: 12

Original Poster
Rep: Reputation: 0
Kenhelm,

Unfortunately the code you suggested ended up deleting my entire smb.conf file.

Code:
sed '/^[[:blank:]]*valid users =/{
h
:a n; /^[[:blank:]]*valid users =/g; ba
}' infile > outfile
 
Old 08-06-2009, 02:14 PM   #8
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 333

Rep: Reputation: 141Reputation: 141
If you mean the output file was empty:
Which version of sed are you using?
Could you post your smb.conf file in code tags to preserve spacing?
I've just tried the sed code on my own smb.conf file and it works as expected.

If you mean the input file was deleted:
Perhaps you used the same file for both input and output.
'infile' and 'outfile' should be different or the contents of the file will be deleted due to redirection '>'.
sed doesn't delete the input file unless the '-i' option is used.
 
Old 08-06-2009, 05:00 PM   #9
Plato
LQ Newbie
 
Registered: Jun 2009
Location: Huntsville, Alabama
Distribution: RHEL 5.3
Posts: 12

Original Poster
Rep: Reputation: 0
Well, your right, I did do /etc/samba/smb.conf > /etc/samba/smb.conf, assuming it would edit itself. I figured a solution out though, which won't require me to even make a share, but to just give new folders that are added 777 permissions so all users can wrx them.. less clutter this way I suppose.

Thanks again for you help everyone.
 
Old 08-07-2009, 01:48 AM   #10
synss
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian, Gentoo, Mac OS X
Posts: 137

Rep: Reputation: 22
Quote:
Originally Posted by Plato View Post
but to just give new folders that are added 777 permissions so all users can wrx them.. less clutter this way I suppose.
That looks dangerous, what about having the users part of a common group and setting the permission to 775?
 
  


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
copying a file enrique_arong Linux - Newbie 5 07-29-2004 01:21 PM
Question on File System and File Copying hey_joe Linux - Newbie 2 11-05-2003 11:30 AM
copying file ronss Linux - Software 3 08-31-2003 04:04 AM
Copying a File... Nefarious Linux - General 3 11-28-2002 01:23 AM
Copying a file tgonetwork Linux - Newbie 3 01-16-2002 11:08 AM


All times are GMT -5. The time now is 04:41 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