2015-11-02 44 views
0

我有一个Postgresql函数,它返回JSON字符串的表。从Postgresql获取行的Bash脚本

我想在Linux平台下获取这些行和这样每个字符串运行卷曲程序:

curl http://XXX.XX.XX.XX:XXXX/update/json -H 'Content-type:application/json' -d ['||solr_interface.dict_cursor_okpd_json()||']' 

你有例子,如何使用这个说bash脚本做什么?

谢谢你的建议。

+0

我看不到卷曲的部分是如何相关的,除非你甚至不知道如何将字符串保存到参数,并在以后进行扩展在bash有用。不妨编辑它,因为它会混淆问题。 – 4ae1e1

+0

是的,我明白了。问题的主要问题是如何获取行usig bash脚本。提到卷曲是我想要得到的结果。 –

回答

0

我找到了解决方案。也许它会为别人

#!/bin/bash 

if [ $# != 2 ]; then 
    echo "Please select postgres procedure for data retreaving as first parameter" 
    echo "and Solr index name (dictionary or company) as second parameter" 
    exit 1; 
fi 

PSQL=/usr/bin/psql 

DB_USER="xxxxxxxx" 
DB_PASSWORD="xxxxxxxx" 
DB_HOST="xxx.xxx.xxx.xxx" 
DB_PORT="xxxx" 
DB_NAME="portal_sources" 

export PGPASSWORD=$DB_PASSWORD 

$PSQL \ 
    -X \ 
    -h $DB_HOST \ 
    -p $DB_PORT $DB_NAME \ 
    -c "select 'curl http://xxx.xxx.xxx.xxx:xxxx/solr/$2/update/json -H ''Content-type:application/json'' -d ''['||$1||']'''" \ 
    --single-transaction \ 
    --set AUTOCOMMIT=off \ 
    --set ON_ERROR_STOP=on \ 
    --no-align \ 
    -t \ 
    --field-separator ' ' \ 
    --quiet \ 
| while read command ; do 
    #echo "$command" 
    eval $command 
done