25 lines
522 B
Bash
25 lines
522 B
Bash
#!/bin/bash
|
||
|
||
# Edit 2020/04/16
|
||
|
||
# sql script
|
||
# https://blog.csdn.net/Hehuyi_In/article/details/95893869
|
||
# example:
|
||
# sql="select count(*) from pg_stat_activity where state='idle in transaction';"
|
||
# message="处于空闲状态的会话"
|
||
sql=""
|
||
message=""
|
||
|
||
user=postgres
|
||
source /home/$user/.bash_profile
|
||
|
||
|
||
if [ $UID -ne `id -u $user` ];then
|
||
echo -e "\033[31;1mNot Manager of PostgreSQL! \033[0m"
|
||
exit 1
|
||
fi
|
||
|
||
# get value
|
||
valuse=`psql postgres -c "$sql" | sed -n '3p' | sed 's/ //g'`
|
||
|
||
echo "$message=$valuse"
|