2

I am trying to add a new line containing GATEWAY=10.0.10.1 to the /etc/sysconfig/network file on each of 32 slave nodes in a cluster.
I read this post on how to insert a line with sed.

This works for me to add a line to a local file:

sed -i.bak -e "\$aGATEWAY=10.0.10.1" test/test1

This works for me viewing a file on node 32:

pdsh -w n032 cat test/test1

This fails for me trying to add a line to a file on node 32:

pdsh -w n032 sed -i.bak -e "\$aGATEWAY=10.0.10.1" test/test1

With this error:

n032: sed: -e expression #1, char 2: extra characters after command
pdsh@admin: n032: ssh exited with exit code 1

I own the file that I'm trying to change:

pdsh -w n032 ls -al test/test1

The above command shows that I own it and have read and write (rw) permissions.

Why does it fail?

5
  • 1
    Welcome on unix.stackexchange. The error is not referred to permission to write but on sed. Probably you have to escape in a different way the expression "\$aGATEWAY=10.0.10.1" that should be expanded by your local shell.
    – Hastur
    Jul 10 '14 at 8:12
  • @Hastur - "\$aGATEWAY=10.0.10.1" is escaped perfectly well as far as I can tell. What do you mean?
    – mikeserv
    Jul 10 '14 at 8:14
  • 1
    @mikeserv I'afraid that the remote node will see the command so sed -i.bak -e =10.0.10.1 test/test1...
    – Hastur
    Jul 10 '14 at 8:20
  • Oh - I think you're right @Hastur. Probably something like ssh "sed ... -e "\$a..."" - anyway you're definitely right about the error - nothing to do with the file.
    – mikeserv
    Jul 10 '14 at 8:21
  • @mikeserv It should be enough to add single quote ' as ssh sed -e '"\$a..."'.
    – Hastur
    Jul 10 '14 at 11:12
5

Ok try with this command line:

pdsh -w n032  sed -i.bak -e '"\$aGATEWAY=10.0.10.1"' test/test1;

With ssh it works. If it works locally (on the nodes) the simple command, it should work this line too.

When you try without quote ', the shell locally (on the current shell on entry computer) will expand and transform for the node the line in:

sed -i.bak -e =10.0.10.1 test/test1

and you will read that error.

Maybe you can find interesting e.g. this chapter or this other.

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.