【问题标题】:Bash script for psqlpsql 的 Bash 脚本
【发布时间】:2014-03-12 07:30:20
【问题描述】:

这是我要运行的 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';

【问题讨论】:

    标签: psql


    【解决方案1】:

    代替

    $(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};"`
    

    【讨论】:

    • 这就是我最终使用的: COMMAND=$'psql -U asm -d asm -t -c \"update zr_fsinstance set lu_order=\'1\' where managementaccesspointhostname = \''$ CE1\'';"' echo $COMMAND eval $COMMAND
    猜你喜欢
    • 2021-08-07
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 2020-03-05
    • 2019-04-15
    • 1970-01-01
    • 2014-10-04
    • 2018-01-08
    相关资源
    最近更新 更多