Skip to content

Instantly share code, notes, and snippets.

@riton
Last active August 29, 2015 14:04
Show Gist options
  • Save riton/b6ff5f0c83f0bdc22e2f to your computer and use it in GitHub Desktop.
Save riton/b6ff5f0c83f0bdc22e2f to your computer and use it in GitHub Desktop.
augeas_etc_services

I try to add the following line sane-port 6566/tcp sane saned # SANE network scanner daemon in my /etc/services file using augeas Services.lns.

# services_sample.augtool
# sane-port       6566/tcp        sane saned      # SANE network scanner daemon
defnode resource /files/etc/services/service-name[. = 'sane-port'][protocol = 'tcp'] 'sane-port'
set $resource/port 6566
set $resource/protocol tcp 
set $resource/#comment "SANE network scanner daemon"
set $resource/alias[last()+1] sane
set $resource/alias[last()+1] saned
save
print /augeas//error

used with augtool -f services_sample.augtool gives following output

error: Failed to execute command
saving failed (run 'print /augeas//error' for details)
/augeas/files/etc/services/error = "put_failed"
/augeas/files/etc/services/error/path = "/files/etc/services/service-name"
/augeas/files/etc/services/error/lens = "/usr/share/augeas/lenses/dist/services.aug:75.15-77.33:"
/augeas/files/etc/services/error/message = "Failed to match \n    { /port/ = /[0-9]+/ }{ /protocol/ = /[A-Za-z]+/ }({ /alias/ = /[*+.-9A-Z_a-z-]+/ })*({ /#comment/ = /[^\\001-\\004\\t\\n\\r ][^\\001-\\004\\n]*[^\\001-\\004\\t\\n\\r ]|[^\\001-\\004\\t\\n\\r ]/ } | ())\n  with tree\n    { \"port\" = \"6566\" } { \"protocol\" = \"tcp\" } { \"#comment\" = \"SANE network scanner daemon\" } { \"alias\" = \"sane\" } { \"alias\" = \"saned\" }"

shell returned 1

I've observed that

  1. The following works
# sane-port       6566/tcp        sane saned      # SANE network scanner daemon

defnode resource /files/etc/services/service-name[. = 'sane-port'][protocol = 'tcp'] 'sane-port'
set $resource/port 6566
set $resource/protocol tcp
set $resource/#comment "SANE network scanner daemon"
#set $resource/alias[last()+1] sane
#set $resource/alias[last()+1] saned

save

print /augeas//error

with proper modification in /etc/services file

  1. The following works too
# sane-port       6566/tcp        sane saned      # SANE network scanner daemon

defnode resource /files/etc/services/service-name[. = 'sane-port'][protocol = 'tcp'] 'sane-port'
set $resource/port 6566
set $resource/protocol tcp
#set $resource/#comment "SANE network scanner daemon"
set $resource/alias[last()+1] sane
set $resource/alias[last()+1] saned

save

print /augeas//error

with proper modification in /etc/services file

Using both #comment and alias seems to be the issue there with this configuration

# rpm -qa '*augeas*'
ruby-augeas-0.4.1-3.el6.x86_64
augeas-1.0.0-5.el6_5.1.x86_64
augeas-devel-1.0.0-5.el6_5.1.x86_64
augeas-libs-1.0.0-5.el6_5.1.x86_64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment