How can I properly watch psql command?

Viewed 1953

Seed

I seed my database

curl -s http://site/api/seed/user/1000

Test

I did

psql --username=nm -d portal -h 192.168.1.27 -c "SELECT count(*) from users;"

I got

 count                                                                                                                                                                                 
-------                                                                                                                                                                                
  1000                                                                                                                                                                                 
(1 row)

Watch

watch psql --username=nm -d portal -h 192.168.1.27 -c "SELECT count(*) from users;"

I got

Every 2.0s: psql --username=nm -d portal -h 192.168.1.27 -...  bh-macbook-pro-15-512gb.local: Tue Nov 21 15:19:08 2017

sh: -c: line 0: syntax error near unexpected token `('                                                                         
sh: -c: line 0: `psql --username=nm -d portal -h 192.168.1.27 -c SELECT count(*) from users;' 

How can I fix this error?

1 Answers

Provide the command as a single, quoted argument:

watch 'psql --username=nm -d portal -h 192.168.1.27 -c "SELECT count(*) from users;"'
Related