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='temps.sh' 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
This command will return any lines containing Temps from the http file it has gotten from 192.168.1.1.
This is not a proper way to call your script, if that is what you are trying to do.
It isn't necessary to configure a web server for curl to pull up a script from any linux device on an internal network. Temp.sh contains the following
#!/bin/bash
cpuTemp0=$(cat /sys/class/thermal/thermal_zone0/temp)
cpuTemp1=$(($cpuTemp0/1000))
cpuTemp2=$(($cpuTemp0/100))
cpuTempM=$(($cpuTemp2 % $cpuTemp1))
Not true, the curl command returns nothing from openwrt. e.g. if I try this on a iMac terminal executing
curl -s http://192.168.1.1 | grep Temps
it goes back to my prompt.
It appears, to me, that the temp.sh 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
Let me try to explain.
The temp.sh (script file) is located in the root home directory.
alias Temps='/root/temps.sh' 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 192.168.1.1 | grep Temps
or from my external program curl -s http://192.168.1.1 | 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, temp.sh, 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.
#!/bin/sh
# gather data...
#send the most minimal header to meet http standard-- the blank line is important.
echo "Content-type: text/utf8"
echo
#send the data
echo "The temperature is $DATA"
On a remote machine, the data can be accessed with curl http://192.168.1.1/something.cgi 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.