HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (http://www.howtoforge.com/forums/index.php)
-   Programming/Scripts (http://www.howtoforge.com/forums/forumdisplay.php?f=7)
-   -   Bash "HERE documents " help (http://www.howtoforge.com/forums/showthread.php?t=56402)

woodson2 2nd March 2012 02:44

Bash "HERE documents " help
 
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?

Code:

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


nbhadauria 7th May 2012 07:56

You can use sed command to append the config into file:

sed -i '/^SEARCHPATTERN/ a\
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,d c=abclott,dc=lott" write\
by dn.base="uid=ldapmgr,ou=people,dc=abclott,dc=lott" write\
by * none' /etc/ldap/slapd.conf

Or even you can insert config.txt file in the config:

sed -i '/^SEARCHPATTERN/r config.txt' /etc/ldap/slapd.conf


All times are GMT +2. The time now is 00:44.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.