Click to See Complete Forum and Search --> : How do I create a file that can read from the /proc files?
godzakka
11-09-2002, 07:54 PM
I want to create a file that reads my sensors, and displays them in a simple word editor, like KEdit or Emacs. How do I do that?
To my best understanding, its just a matter of telling it what I want, and then how to display them.
All of my files are under /proc/sys/dev/sensors/w83697hf-isa-0290 and they are as follows:
temp1
temp2
in0
in2
in3
in4
in5
in6
in7
in8
That is all I want displayed. If someone can show my how to call any one of those to be printed to a screen, I know I can do the rest.
Thanks so much.
Mnemonic
11-09-2002, 08:06 PM
Originally posted by godzakka
I want to create a file that reads my sensors, and displays them in a simple word editor, like KEdit or Emacs. How do I do that?
Have you considered redirecting like the following:
cat /proc/dev/system/whatever > sensor.out 2>&1
...then append the sensor.out file with whatever2, whatever2, etc.
godzakka
11-09-2002, 08:29 PM
Here's what I got so far, and I just read yours and its going in the direction I need it, but I just don't understand how to do what you suggested (I am still pretty new)
Mine reads like:
start:
cat /proc/sys/dev/sensors/w83697hf-isa-0290/temp1
echo "System Temp"
cat /proc/sys/dev/sensors/w83697hf-isa-0290/temp2
echo "CPU Temp"
cat /proc/sys/dev/sensors/w83697hf-isa-0290/in0
echo "Vcore"
cat /proc/sys/dev/sensors/w83697hf-isa-0290/in2
echo "+3.3V line"
cat /proc/sys/dev/sensors/w83697hf-isa-0290/in3
echo "+5V line"
etc etc etc
end
I am getting an output like:
start:
60.0 127.0 30.0
System Temp
60.0 50.0 42.0
CPU Temp
4.08 4.08 1.74
Vcore
etc etc etc
end
I want to take the last number that it is outputting, the 30, 42, 1.74, etc, and then display those followed by the "echo 'System Temp'" or whatever label I want.
I would also like to multiply some of the results (for instance, the +5V line) by a given factor and then output it.
Anymore help, thanks so much.
Mnemonic
11-09-2002, 08:41 PM
Do you program in C? It seems this would be very easy to do. It has been quite some time since I have done any programming, but I am formulating a method as we type.
I am not certain, but I think that floating point math is not able to be done in a shell script? I could be wrong, but I thought integer math was all you could do in script-wise.
godzakka
11-09-2002, 09:15 PM
I don't program, but I have a vague knowledge of C++ and MatLab, and I am currently learnign to use APL in my Crypto class. I know its possible, I just want to get it to work so I learn how to manipulate the data output in linux.
Thanks in advance for any help you give me.
Mnemonic
11-09-2002, 09:32 PM
Originally posted by godzakka
I don't program, but I have a vague knowledge of C++ and MatLab, and I am currently learnign to use APL in my Crypto class. I know its possible, I just want to get it to work so I learn how to manipulate the data output in linux.
Thanks in advance for any help you give me.
Ok...a good place to look for such information is the Rute User's Tutorial and Exposition at http://rute.sourceforge.net. Specifically chapters 7 and 8 will be of interest. You might end up using grep to parse lines. It appears that floating point math is allowable. I still am not confident that floating point math can be done as a shell script.
godzakka
11-09-2002, 10:43 PM
So far that is providing to be very useful. But I am at a problematic point, if you can help out:
I want to echo the 3rd, 6th, 9th, etc until the 30th line of my output file. I can get it to do 3, 6 and 9, but when I put 12, it reads 1. When I put 21, it reads 2. How do I fix this?
Mnemonic
11-09-2002, 10:45 PM
Originally posted by godzakka
So far that is providing to be very useful. But I am at a problematic point, if you can help out:
I want to echo the 3rd, 6th, 9th, etc until the 30th line of my output file. I can get it to do 3, 6 and 9, but when I put 12, it reads 1. When I put 21, it reads 2. How do I fix this?
Can you provide a snippet of code so that I can see what you are working?
godzakka
11-09-2002, 11:08 PM
my sensors update is this:
"cat /proc/sys/.../temp1 > sensor.out
cat /proc/sys/.../temp2 >> sensor.out
...
...
...
cat /proc/sys/.../in8 >> sensor.out"
I then wrote a shell script, which is like this:
"#!/bin/sh
echo "System Temp: $3 F"
echo "CPU Temp: $6 F"
echo "Vcore: $9 V"
echo "+3.3V line: $12 V"
...
...
...
echo "+5BAT line: $30 V"
Where I have the bold is where the problem starts.
"sensor.out" looks like this:
"60.0 127.0 30.0
60.0 50.0 42.0
4.08 4.08 1.74
2.97 3.63 3.21
2.68 3.26 2.94
...
...
...
2.70 3.29 3.18"
Where the bold is are the actual numbers I want to pop out. The first 30 is my system temp, the 42 is my CPU temp, the 1.74 is my Vcore, the 3.21 is my 3.3V line, the next line, the 2.94, needs to be multiplied by 1.68 and then output, but that will be my next challenge.
Mnemonic
11-10-2002, 12:47 AM
Here is something I got to playing with that you might be able to use. If you have any questions about what is happening here, please let me know.
#!/bin/sh
X=`cat ~/test.dat | egrep -wo '(3|4).*'`
echo $X
godzakka
11-10-2002, 01:11 AM
Ok, I have the sensor.out file being created by a shell file, and then another shell file reads like this:
"#!/bin/sh
echo "System Temp: $3 F"
...
...
echo "+5V line: ${12} V"
echo "+12V line: ${18} V"
...
..."
So all it took was putting the {} around the numbers I want.
I am still trying to figure out how to modify the numbers before they come out and also how to make a shortcut so that when I type "sen" or something else that I choose, the system reads this file regardless of what directory I am in.
Thanks for your help, I would've never made it this far without that link you provided.
Mnemonic
11-10-2002, 01:21 AM
I guess my question would be why would you want to have to run two scripts for a single task?
Anyhow, placing your script(s) in /usr/bin (or any other directory for which the path is defined) will allow you to type the command at a command prompt.
Or for a desktop link you could use something like:
rxvt -e scriptname
godzakka
11-10-2002, 01:50 AM
Why use more than one script? Because its my first time. I am just learning, but I am getting a better understanding as I go.
I am now trying to figure out how to modify the values before they get echo'ed to the screen.
I am assuming they are being read as characters or strings, and then displayed. My goal is to figure out how to grab that string, do a mathematical operation on it, and then display it on the screen.
Suggestions, ideas, always welcome. Thanks again.
Mnemonic
11-10-2002, 03:09 AM
The Rute online information was so worthwhile that I made the purchase of the book. Until this evening I had not even tried to write a shell script much more than invoking an app with command line argumants in place. :D
godzakka
11-10-2002, 04:38 AM
Any idea how to take a string and multiply that string by a given number, say 2 or 3.5 or 1.68 or whatever? Thats my problem now. Its proving to be quite difficult too.
justfreemcco
11-10-2002, 04:45 AM
...something like this:
X=`expr 100 + 50 '*' 3`
echo $X
???
Mnemonic
11-10-2002, 08:31 AM
Originally posted by godzakka
Any idea how to take a string and multiply that string by a given number, say 2 or 3.5 or 1.68 or whatever? Thats my problem now. Its proving to be quite difficult too.
That is why I was questioning the ability to do floating point math in a shell script and then mentioned programming this whole thing using C. I am not certain it can be done.
godzakka
11-10-2002, 08:39 AM
Right. And to justfreemmco, I have tried all the variations on that exact method, but thanks, I do appreciate you helping out too.
Mnemonic, how hard is it to write it in C? I am almost done with this (except for getting the string to be a number, which I can easily do in APL but not in linux, figures).
Mnemonic
11-10-2002, 09:05 AM
I think that it would be very easy to do...either make a few system calls and write the info to a file (like you are doing now). Then make a single file open and a few reads...or open a few files and make single reads from each. Once you have the data read in, the battle is basically won. However, I would probably end up writing some function that read a string character by character to do my parsing even though there is some easier way of handling the data. Shoot! It has been so long since I have done any programming I do not know if I have any of my C manuals lying around. That should be ok because all the information should now be online, right?
justfreemcco
11-10-2002, 04:21 PM
how about:
answer=`echo "scale=2; ($3*1.68) | bc`
echo $answer
godzakka
11-10-2002, 05:26 PM
Nope, that tells me that $3 (30.0), that 30.0*1.68 is not a function.
justfreemcco
11-10-2002, 05:42 PM
$3=`echo "scale=2; ($3*1.68) | bc`
echo $3
??
do you have any interface for your sensors?
or:
echo $3 | awk '{printf( "%2.2f\n", ($1*1.68)}'