Created
August 15, 2015 19:16
-
-
Save miso4ru/2d9c96e3dc84be6aa48d to your computer and use it in GitHub Desktop.
Redshiftに簡単なクエリ投げたいとき用 shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CMDNAME=`basename $0` | |
# parameters | |
## 1.Redshift | |
RSHOST='' # endpoint | |
RSPORT=5439 | |
RSNAME='' | |
RSUSER='' | |
RSPASS='' | |
## 2.sample query | |
QUERY=$( cat << EOF | |
CREATE TABLE test ( | |
id int, | |
message varchar(max) | |
); | |
EOF | |
) | |
# password set | |
export PGPASSFILE=`mktemp /tmp/pass.XXXXXX` | |
cat >$PGPASSFILE << EOF | |
$RSHOST:$RSPORT:$RSNAME:$RSUSER:$RSPASS | |
EOF | |
logger="/usr/bin/logger -i -p local1.info -t ${CMDNAME}" | |
# Send Query | |
echo "Send Query" | $logger | |
echo "$QUERY" | $logger | |
psql -d $RSNAME -h $RSHOST -p $RSPORT -U $RSUSER -c "$QUERY" 2>&1 | $logger | |
rm -f $PGPASSFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment