I'd like to ensure that I have the lines ...
root: /dev/null
greenman: /dev/null
... in my /etc/aliases
file and I have been learning about augtool
. I know I could do something like this with augtool ...
$ sudo augtool set /files/etc/aliases/15/name greenman
... but I do not like hard coding the 15
. It is quite possible on some systems greenman: /dev/null
might be the 10th name/value pair. Is there a way to avoid using a number in /files/etc/aliases/15/name
?
Thanks
Working with
seq
entries (these numbered entries, such as15
in your case) in Augeas can be a little bit tricky.Using
augtool
stillYou can make yourself an augtool script that looks like this:
The shebang (
#!/usr/bin/augtool -sf
) uses-s
to automatically save after making the changes, and-f
to take a file with commands, making it a self-executable script, so you can just make the file execuable and run it:If you don't want to make the script executable, you can also pass it to
augtool
:And if you don't want to use
--autosave
, you can addsave
as the last line of the script.Using a "real" programming language
Bash is nice, but coping with its limits can lead to complex solutions. Augeas has lots of bindings in many languages. Just pick one and it will get easier to write your code, because you will be able to use a persistent Augeas handler. Here is an example with Ruby:
Using Puppet
In Puppet, the best solution is to rely on the
mailalias
type with theaugeas
provider from augeasproviders. It uses the Augeas Ruby library to safely edit/etc/aliases
:Note:
mailalias
is a standard Puppet type, but the default provider doesn't use Augeas.