0

please advice what is wrong with my sed syntax ?

ssh [email protected] sed -i '/archive_command/ s/#BARMAN#[ ]*//g'  /var/lib/pgsql/data/postgresql.conf"

sed: -e expression #1, char 17: missing command

my target is to remove the #BARMAN# string on remote machine

when I do this on local machine its works as the following:

sed -i '/archive_command/ s/#BARMAN#[ ]*//g'  /var/lib/pgsql/data/postgresql.conf"
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
yael
  • 12,598
  • 51
  • 169
  • 303

1 Answers1

0

The syntax is wrong.

It has to be :

ssh postgres@host 'sed -i "/archive_command/ s/#BARMAN#[ ]*//g"  /var/lib/pgsql/data/postgresql.conf"'

You forgot the quotes before and after the command. And added double quotes instead of single quotes so that there is no need to escape it.

Hunter.S.Thompson
  • 8,839
  • 7
  • 26
  • 41
  • Careful - there are single-quotes as part of the sed command, which will leave them exposed to splitting. – Jeff Schaller Sep 13 '17 at 15:36
  • Updated my answer to escape the quotes. @JeffSchaller Edit if I made a mistake. I am not sure if the escaping is done right. – Hunter.S.Thompson Sep 13 '17 at 15:39
  • Since there are no double-quotes or variables in the listed command, wrapping it with double quotes would work for this particular Q. – Jeff Schaller Sep 13 '17 at 15:40
  • Updated with double quotes. @yael I might not know `sed` too well, So I ask, is this the right syntax? `/var/lib/pgsql/data/postgresql.conf"` With only a single double quote at the end of `.conf` ? – Hunter.S.Thompson Sep 13 '17 at 15:43