psql的Bash脚本

时间:2014-02-13 12:12:38

标签: psql

这是我尝试运行的shell脚本。它只在作为命令运行时运行,但在从脚本运行时会出现错误。

#!/bin/bash

# sets CE IP addresses to act as LUS on pgsql

#Checks that user is logged in as root
if [ $(id -u) = "0" ]; then
        #Asks user for IP of CE1
        echo -n "Enter the IP address of your first CE's management module > "
        read CE1

        $(psql -U asm -d asm -t -c) echo """update zr_fsinstance set lu_order='1' where     managementaccesspointhostname = '$CE1';"""

        echo "LUS seetings have been completed"

else
        #Warns user of error and sends status to stderr
        echo "You must be logged in as root to run this script." >&2
        exit 1
fi

这是错误:

psql: option requires an argument -- 'c'
Try "psql --help" for more information.
update zr_fsinstance set lu_order='1' where managementaccesspointhostname = '10.134.39.139';

1 个答案:

答案 0 :(得分:0)

而不是

$(psql -U asm -d asm -t -c) echo 
"""update zr_fsinstance 
set lu_order='1' where managementaccesspointhostname = '$CE1';"""

尝试:

$(psql -U asm -d asm -t -c "UPDATE zr_fsinstance set lu_order='1' 
  where managementaccesspointhostname = ${CE1};")

或(如果您愿意):

`psql -U asm -d asm -t -c "UPDATE zr_fsinstance set lu_order='1' 
 where managementaccesspointhostname = ${CE1};"`