问题
I am new in bash and psql, I want to write a bash code that login a server the connect to psql database do a select query and then return the output. the set up I have as follow.
server named dbs, it has psql install and running. database name = dname, user= tester passwrod = 1234 in the database there is table called node_info it has 3 colons ip, mac, connection_time. I want to run following query select ip, connection_time from node_info where ip=10.10.10.2;
Any tips how to write a shell script to do this remotely?
回答1:
If you have properly set your "pg_hba.conf" configuration file to achieve remote connections, you may try the following:
psql -U tester -h remoteip -p remoteport -d dname -W -c "select ip, connection_time from node_info where ip='10.10.10.2'"
来源:https://stackoverflow.com/questions/28688765/run-psql-query-in-bash