Question

Here is the shell script I am trying to run. It works when just run as a command but getting errors when run from the script.

#!/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

Here is the error:

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';
Was it helpful?

Solution

Instead of

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

Try:

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

OR (if you prefer):

`psql -U asm -d asm -t -c "UPDATE zr_fsinstance set lu_order='1' 
 where managementaccesspointhostname = ${CE1};"`
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top