Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a variable in a bash script that contains the data from a postgres database

I'm looking to create a script than can find a specific date/time based on a field in a database Currently i do it manually...

# psql gttvdb -U postgres
gttvdb=# select patch_date from version_history where version ='1.1.1';

What i need is to be able to reference that date as a variable in a bash script

#! /bin/sh
patchdate=$("select patch_date from version_history where version ='1.1.1';")
echo "last update was " $patchdate
like image 483
user1591029 Avatar asked Dec 14 '25 16:12

user1591029


1 Answers

Try this:

patchdate=` psql -t -q -c "select patch_date from version_history where version ='1.1.1'"`
like image 197
Szymon Lipiński Avatar answered Dec 16 '25 06:12

Szymon Lipiński



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!