I need help understanding some pieces of a shell script to connect to a Redshift database because Bash/shell is unfamiliar for me.
to use
pgpass
, is this all I need to get the credentials? :cat > ./.pgpass <<-CREDS $HOSTNAME:$PORT_NUMBER:$DBNAME:$USERNAME:$PASSWORD CREDS
What is
<<-
? Is it a comment? Quick search says that<<END
is a comment but is that anything different from<<-CREDS
?This is somewhat related to #2, what do
<<-ATOMIC
and\x
mean in this snippet?$PSQL_CMD <<-ATOMIC \x SELECT column1 FROM $THETABLE WHERE column1='true'; ATOMIC
Since ATOMIC
is at the end of this block, I would presume that it's stating the end of a block or something, but I don't understand the documentation or anything.
How do I assign the returned value(s) of the
SELECT
statement into a variable and echo it into an email? I have a line to send the email, but don't know how to assign the returned values from theSELECT
query into a variable:$ echo "hello world" | mail -s "Test" [email protected]
I'm not sure what you're trying to do here. To my knowledge,
pgpass
won't contain your credentials unless you've put them in there yourself. This sounds like maybe command to do that.<<-
is not a comment. It represents a 'Here document' See: https://en.wikipedia.org/wiki/Here_document#Unix-ShellsRegarding
<<-ATOMIC
see the above link. The\x
tells psql to format the output from yourSELECT