Curl information question

I have a question about getting cUrl info from my Raspberry, that works on debian but not on openwrt.

I have an alias in both bash.rc and profiles as follows
alias Temps='' which returns the current CPU temperature from the device within dropbear, bash and ash environments. However,
when trying to access that information via curl from my PC it returns nothing

curl -s | grep Temps

Perhaps the etc/profile file or location isn't absolute for the alias parameter?

I'm lost. Can you explain how you configured the web server in OpenWrt?


what @lleachii said.

what happens if you access the same URL by browser ?


This command will return any lines containing Temps from the http file it has gotten from
This is not a proper way to call your script, if that is what you are trying to do.

1 Like

It isn't necessary to configure a web server for curl to pull up a script from any linux device on an internal network. contains the following
cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp)
cpuTempM=$(($cpuTemp2 % $cpuTemp1))

#gpuTemp0=$(/opt/vc/bin/vcgencmd measure_temp)

echo CPU Temp: $cpuTemp1"."$cpuTempM"º C"

This script works on openwrt directly in SSH or bash and bin. It is also accessible on my Raspberry running debian via curl, however not on openwrt.

Not true, the curl command returns nothing from openwrt. e.g. if I try this on a iMac terminal executing
curl -s | grep Temps
it goes back to my prompt.

my Raspberry 4B running debian returns

curl -s | grep Temps
CPU Temp: 44.3º C

Essentially I am trying to monitor the core Temperature from my Raspberry on my desktop using a separate tool that accepts curl.

I am uncertain that any Browser will accept a grep command

You're parsing the output, why wouldn't it work?

:joy:. curl doesn't run in a browser. If I type in the IP address it opens openwrt LUCI :+1:

curl http://.... requires a http server on the other side. Maybe you were using curl ssh mode instead?

The http server installed in OpenWrt by default as a dependency of LuCI can be configured to treat certain URLs as script calls.

The grep command is unnecessary as you can write the server side script to output the format that you want.

It appears, to me, that the script located on my Raspberry running openwrt cannot be accessed since its path or alias isn't identified outside of the open bash or ash session. Not certain as to where else to place the alias other than profiles or bash.rc in the /etc folder.
Debugging I get (0) which indicates file or command not found

Accessed how?

1 Like

Let me try to explain.
The (script file) is located in the root home directory.
alias Temps='/root/' is located in bash.rc and profile under /etc

Since the curl command is making a call directly to the alias externally either using a shell on Mac or linux
curl -s | grep Temps
or from my external program curl -s | grep Temps

I dont believe that its accessible because the alias defined is not reachable outside of a running bash or ash SSH open terminal connection.

I dont know any way to directly run or call up the script file,, directly, outside of an open terminal and the alias method works well on everything else. Maybe dropbear or something else is previnting the script from being found. I dunno

If you have LuCI running on the router, you can easily add your script as another CGI call.

Name the script something.cgi and place it (or a link to it) in /www/cgi-bin. Make sure execute permission is set.

# gather data...
#send the most minimal header to meet http standard-- the blank line is important.
echo "Content-type: text/utf8"
#send the data
echo "The temperature is $DATA"

On a remote machine, the data can be accessed with curl Any http browser should work including wget and GUI browsers. If you want a real html page rather than a simple blob of raw text, you would need to change the content type to text/html and add headers and other markup.


Worked like a charm!

Thank you :grinning:

Screen 2022-12-27 um 19.39.50

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.