Why does this bash script work if called from the command line but not when called from a php script run by a webpage?
by KenHorse from LinuxQuestions.org on (#5NKWV)
More precisely, the variables in the script are not returned to the calling php script
First the call from the php script:
Code:$CPUTemp = exec("/usr/local/sbin/supermon/get_temp");
print " [ $CPUTemp]";Now the bash script:
Code:echo -n "CPU: "
CTEMP=$(/opt/vc/bin/vcgencmd measure_temp)
CTEMP=${CTEMP:5}
SAVE=$IFS; IFS="'"; set -- $CTEMP; IFS=$SAVE
CTEMP=$1; FTEMP=$(echo 9 '*' $CTEMP / 5 + 32 | /usr/bin/bc)
if [ "$FTEMP" -le "120" ]; then
echo -en "<span style=\"background-color: palegreen;\">"
elif [ "$FTEMP" -le "150" ]; then
echo -en "<span style=\"background-color: yellow;\">"
else
echo -en "<span style=\"font-weight: bold; color: yellow; background-color: red;\">"
fi
echo -en " ${FTEMP}°F, ${CTEMP}°C </span> @ `date +%H:%M` "If called from command line:
root@myhost:~# /usr/local/sbin/supermon/get_temp
CPU: <span style="background-color: palegreen;"> 88°F, 31.6°C </span> @ 08:07
root@myhost:~#
The attachment shows what is displayed in browser:
And yes, both scripts are executable by the world
Attached Thumbnails
First the call from the php script:
Code:$CPUTemp = exec("/usr/local/sbin/supermon/get_temp");
print " [ $CPUTemp]";Now the bash script:
Code:echo -n "CPU: "
CTEMP=$(/opt/vc/bin/vcgencmd measure_temp)
CTEMP=${CTEMP:5}
SAVE=$IFS; IFS="'"; set -- $CTEMP; IFS=$SAVE
CTEMP=$1; FTEMP=$(echo 9 '*' $CTEMP / 5 + 32 | /usr/bin/bc)
if [ "$FTEMP" -le "120" ]; then
echo -en "<span style=\"background-color: palegreen;\">"
elif [ "$FTEMP" -le "150" ]; then
echo -en "<span style=\"background-color: yellow;\">"
else
echo -en "<span style=\"font-weight: bold; color: yellow; background-color: red;\">"
fi
echo -en " ${FTEMP}°F, ${CTEMP}°C </span> @ `date +%H:%M` "If called from command line:
root@myhost:~# /usr/local/sbin/supermon/get_temp
CPU: <span style="background-color: palegreen;"> 88°F, 31.6°C </span> @ 08:07
root@myhost:~#
The attachment shows what is displayed in browser:
And yes, both scripts are executable by the world
Attached Thumbnails