What's a working example of modifying /etc/export using bash?


I want to ensure the following rule is present and valid:

/export/home 2400:123::/32(rw,no_root_squash)

And it should:

  1. Add only if it doesn't exist already (in any form)
  2. If it partly exists, it shold update existing entry (e.g options update)

Possible syntaxes in existing file:

  • Multiple whitespaces, and different options

    /export/home 2400:123::/32(rw,no_root_squash,no_subtree_check)

  • Multiple allow on same line

    /export/home 2400:123::/32(rw,no_root_squash,no_subtree_check) 2400:321::/32(rw,no_root_squash,no_subtree_check)

In addition to combinations of the above.

Initially I wanted to use augeas for this, but there's a bug with IPv6 adresses in the /etc/exports file.

The /etc/exports file should allow independent modifying witout breaking the script (which should ensure only the rule in question is correct and valid, and leave the rest of the rules alone)


If you can't use Augeas and Puppet, here's what I would do:

if grep -qF '^/export/home' /etc/exports;then
    sed -i \
    's@^/export/home.*$@/export/home 2400:123::/32(rw,no_root_squash)@'\
    echo '/export/home 2400:123::/32(rw,no_root_squash)' >> /etc/exports

Careful, though: this assumes that any rule for exporting /export/home is fair game for being replaced by your given definition.


I found that the /etc/exports lense for Augeas has been fixed for IPv6 in trunk, and can be imported manually:


Putting this file into /usr/share/augeas/lenses/ makes it take presendence over the default lense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.