I'm trying to send a sed command using ssh.
Here is my script:
#!/bin/bash
IP_PUBLIC="192.168.0.1"
from="DB_HOST='my_host'"
to="DB_HOST='192.168.0.2'"
ssh -oStrictHostKeyChecking=no root@"$IP_PUBLIC" '
sed -i "s/'"$from'"/'"$to'"/g" /path/to/file;
'
Which throw me the following error:
test: line 9: unexpected EOF while looking for matching `''
test: line 10: syntax error: unexpected end of file
I also tried
#!/bin/bash
IP_PUBLIC="192.168.0.1"
ssh -oStrictHostKeyChecking=no root@"$IP_PUBLIC" '
sed -i "s/DB_HOST=\'my_host\'/DB_HOST=\'192.168.0.2\'/g" /path/to/file;
'
I got the same error
Content of the file
#!/bin/bash
DB_HOST='my_host'
Need to be
#!/bin/bash
DB_HOST='192.168.0.2'