LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   calling curl inside .sh file (https://www.linuxquestions.org/questions/linux-newbie-8/calling-curl-inside-sh-file-949292/)

fachhoch@gmail.com 06-08-2012 06:38 PM

calling curl inside .sh file
 
I have setenv.sh file used by tomcat, I can set java otpions in this sh file.
I want to use curl to get a value capture it in a variable and use it as a java opts its not working , please help me .Here is my script
Code:

#!/bin/sh
export JAVA_HOME=/opt/java
export JAVA_OPTS="-Xms1024m -Xmx1024m -XX:MaxPermSize=256m"
JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote.ssl=false"
JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote.authenticate=false"
PUBLIC_DNS=curl http://169.254.169.254/latest/meta-data/public-hostname

#export PUBLIC_DNS="${PUBLIC_DNS}"
JAVA_OPTS="${JAVA_OPTS} -Djava.rmi.server.hostname=${PUBLIC_DNS}"
echo "JAVA_OPTS=${JAVA_OPTS}"
CATALINA_PID=/var/run/tomcat.pid

I am assuming PUBLIC_DNS=curl http://169.254.169.254/latest/meta-data/public-hostname will get the value into PUBLIC_DNS , but this is always blank.
Please advice me whats wrong.

notihnio 06-09-2012 01:54 AM

try to replace
Code:

PUBLIC_DNS=curl http://169.254.169.254/latest/meta-data/public-hostname
with
Code:

PUBLIC_DNS='curl http://169.254.169.254/latest/meta-data/public-hostname'

414N 06-09-2012 02:02 AM

Quote:

Originally Posted by notihnio (Post 4699276)
try to replace
Code:

PUBLIC_DNS=curl http://169.254.169.254/latest/meta-data/public-hostname
with
Code:

PUBLIC_DNS='curl http://169.254.169.254/latest/meta-data/public-hostname'

Nope. You have to use backticks instead of single quotes or the $(cmd) form.
The correct forms are
Code:

PUBLIC_DNS=`curl http://169.254.169.254/latest/meta-data/public-hostname`
PUBLIC_DNS=$(curl http://169.254.169.254/latest/meta-data/public-hostname)



All times are GMT -5. The time now is 03:59 PM.