Skip to content

Instantly share code, notes, and snippets.

@longkey1
Created January 25, 2013 04:16
Show Gist options
  • Save longkey1/4631687 to your computer and use it in GitHub Desktop.
Save longkey1/4631687 to your computer and use it in GitHub Desktop.
connect to postgres database by psql
#!/bin/sh
## setting area
SETTING_LIST="hoge1 hoge2 hoge3"
hoge1="user1 database1 xxx.xxx.xxx.xxx"
hoge2="user1 database2 localhost"
hoge3="user1 database3 host3"
## setting area
if [ "$1" ] ; then
SETTING_NAME=$1
eval SETTING=\${$1}
fi
if [ ! "$SETTING" ] ; then
echo "plese setting name. example..."
for SETTING_NAME in $SETTING_LIST
do
eval SETTING=\${$SETTING_NAME}
echo "${SETTING_NAME} > ${SETTING}"
done
exit
fi
i=0
for var in $SETTING
do
if [ $i -eq 0 ]; then
USER=$var
elif [ $i -eq 1 ]; then
DB=$var
elif [ $i -eq 2 ]; then
HOST=$var
fi
i=`expr $i + 1`
done
echo "connect... ${SETTING_NAME} : \"psql -U ${USER} -d ${DB} -h ${HOST}\""
psql -U ${USER} -d ${DB} -h ${HOST}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment