shell 获取 postgresql返回字段值

来源:互联网 发布:东安格利亚大学 知乎 编辑:程序博客网 时间:2024/06/14 05:48
databasename=rftDatabase
result=`psql << EOF 
  SELECT count(u.datname) FROM pg_catalog.pg_database u where u.datname='${databasename}'; 
EOF`


DBID=`echo $result | awk -F' ' '{print $3}'`
echo "${DBID}"
if [ "${DBID}" = "0" ]; then
   echo "count=0"
else 
   echo "count>0"
fi 
 
0 0
原创粉丝点击