Find the answer to your Linux question:
Results 1 to 3 of 3
I'm trying to run the following command: Code: tmp=$(psql --quiet --tuples-only -U opennms -d opennms -h localhost -p 5432 -c "select nodeid from ifservices where ipaddr = $HOSTNAME limit 1;") ...
  1. #1
    Just Joined!
    Join Date
    Aug 2007
    Posts
    12

    problem reading variable in script

    I'm trying to run the following command:

    Code:
    tmp=$(psql --quiet --tuples-only -U opennms -d opennms -h localhost -p 5432 -c "select nodeid from ifservices where ipaddr = $HOSTNAME limit 1;")

    But I keep getting an error when inserting the script variable '$HOSTNAME'. The error I get is the following:

    [quote]
    ERROR: syntax error at or near ".128" at character 52
    [quote]

    what is causing this error and what do I need to do in order to correct the problem?

    thanks in advance.

  2. #2
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    452
    $HOSTNAME is not a command; try `echo $HOSTNAME`
    the sun is new every day (heraclitus)

  3. #3
    Just Joined!
    Join Date
    Jul 2007
    Posts
    41
    Is the error coming from the database?

    Try enclosing the variable in quotes:

    Code:
    tmp=$(psql --quiet --tuples-only -U opennms -d opennms -h localhost -p 5432 -c "select nodeid from ifservices where ipaddr = \"$HOSTNAME\" limit 1;")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...