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;")
...
- 09-07-2007 #1Just 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.
- 09-07-2007 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
$HOSTNAME is not a command; try `echo $HOSTNAME`
the sun is new every day (heraclitus)
- 09-07-2007 #3Just 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;")


Reply With Quote