I want to update a column of my database running in a VW (using Vagrant
) with the host's IP.
To do this I want to use a bash script:
LOCAL_IP=$(ipconfig getifaddr en0)
SQL="vagrant ssh -c 'psql -U user -d mydatabase -h localhost -c \"update mytable set mycolumn = '$LOCAL_IP';\"'"
eval $SQL
But I get this error:
ERROR: syntax error at or near ".123"
LINE 1: update mytable set mycolumn = 123.123.123.123;
The ouput of the SQL vriable:
echo $SQL
vagrant ssh -c 'psql -U user -d mydatabase -h localhost -c "update mytable set mycolumn = '123.123.123.123';"'
When I call the psql command from echo $SQL
in the vm everything is fine, but I don't have the host ip.
vagrant ssh
psql -U user -d mydatabase -h localhost -c "update mytable set mycolumn = '123.123.123.123';"
It looks like the vagrant ssh -c
command would remove the single quotes around the IP. Any ideas?
UPDATE
Easiest way to reproduce my problem:
$ vagrant ssh -c 'echo "update table set column = 'test';" > bla.sql'
$ vagrant ssh
$ cat bla.sql
update table set column = test;