1,105,644 Community Members

Help with "HERE" documents

Member Avatar
woodson2
Newbie Poster
3 posts since Jun 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I'm trying to enter a block of text into an existing configuration file for OpenLDAP so the setup can be fully scripted.

The text below is what I want to enter into slapd.conf and this all works well and good, however as you probably know this will place the text at the end of the file. What I'd like to know is how can I choose where in an existing file I want to place the text or is this beyond the scope of HERE documents?

cat >> slapd.conf << "EOF"
access to attrs=userPassword
        by self write
        by anonymous auth
        by dn.base="cn=root,dc=abclott,dc=lott" write
        by group.base="cn=infrastructure,ou=GTECH,ou=groups,dc=abclott,dc=lott" write
        by dn.base="uid=ldapmgr,ou=people,dc=abclott,dc=lott" write
        by * none

access to dn.children="ou=people,dc=abclott,dc=lott"
        by dn.base="cn=root,dc=abclott,dc=lott" write
        by dn.base="cn=bind,dc=abclott,dc=lott" read
        by users read
        by * none

access to dn.children="ou=groups,dc=abclott,dc=lott"
        by dn.base="cn=root,dc=abclott,dc=lott" write
        by dn.base="cn=bind,dc=abclott,dc=lott" read
        by users read
        by * none

access to dn.children="ou=servers,dc=abclott,dc=lott"
        by dn.base="cn=root,dc=abclott,dc=lott" write
        by group.base="cn=infrastructure,ou=GTECH,ou=groups,dc=abclott,dc=lott" write
        by dn.base="cn=bind,dc=abclott,dc=lott" read
        by users read
        by * none

access to dn.subtree="ou=SUDOers,dc=abclott,dc=lott"
        by dn.base="cn=root,dc=abclott,dc=lott" write
        by dn.base="cn=bind,dc=abclott,dc=lott" read
        by users read
        by * none

access to *
        by dn.base="cn=root,dc=abclott,dc=lott" write
        by dn.base="cn=bind,dc=abclott,dc=lott" search
        by * none
EOF
Member Avatar
L7Sqr
Veteran Poster
1,006 posts since Feb 2011
Reputation Points: 179 [?]
Q&As Helped to Solve: 168 [?]
Skill Endorsements: 11 [?]
 
0
 

Well, the effect is due to how your are writing ( >> ) to the file not necessarily due to the HERE document. I can think of a couple of solutions that may work depending on your setup.

If you have a set front matter and tail matter you can place them in separate files and change your script to:

cat frontmatter.cfg > slapd.conf
cat >> slapd.conf <<EOF
your dynamic data here
EOF
cat tailmatter.cfg >> slapd.conf

If you can't do that then you can always place the surrounding parts of the file in the HERE document.

If you want to choose a distinct location to insert each time you use the HERE document I think you will have to move to a non-command-line approach and script it up in something else like perl, awk, ruby or even a bash script.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article