0

I would to replace a string with sed command in ssh from local to remote.

The file is /data/PGSQL9.x/postgresql.conf and I would like to change the string listen_addresses = '*' to listen_addresses = 'localhost'

I have to be root, so I do this :

ssh root@myRemoteAddr 's,listen_addresses = '\''\*'\'',listen_addresses = '\''localhost'\'',g' /data/PGSQL9.x/postgresql.conf

And I have this message : sed -e expression #1, char 18: unterminated ``s' command

And when I use "/data/PGSQL9.x/postgresql.conf" I have the same message.

  • Huh? The `ssh` command you posted doesn't call `sed` at all. – Charles Duffy Jan 09 '18 at 16:54
  • 1
    Also, note that in general, passing your remote command as separate arguments to `ssh` rather than a single string is a bad idea. ssh just combines them into a string in a manner equivalent to `sh -c "$*"`, so you lose information about where individual arguments start and end and how they were quoted. – Charles Duffy Jan 09 '18 at 16:55
  • Short form: `ssh root@myRemoteAddr 'bash -s' <<'EOF'`, put your code on separate lines, and end with `EOF`. – Charles Duffy Jan 09 '18 at 16:58
  • @CharlesDuffy It's not the same question ... I had errors when I have tried the answer of the other question. But using " neither ' it works, thank you :) –  Jan 09 '18 at 17:15
  • I didn't say either of those *would* work. Regardless -- please [edit] the question to show *how* you tried to apply to accepted answer of the other question, and exactly how it fails. It wouldn't hurt to show the successfully-tested local command you're trying to remotely invoke. – Charles Duffy Jan 09 '18 at 17:17
  • And once again, your `ssh` command *doesn't even invoke `sed` at all*, so it can't possibly be generating the `sed`-specific error message you include in the question -- meaning the ssh command in the question is different from the ssh command you're actually running. We ask that questions provide a [mcve] -- the shortest possible code *that actually generates the exact error you're asking about* when run by someone else. Bugs that prevent code from being tested mean that we can't reproduce your problem, and can't reproduce your answer. – Charles Duffy Jan 09 '18 at 17:19

0 Answers0