ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
First of all, being a previous Microsoft Slave, being pretty good at VB, I got fed up and pretty much completely switched all my PC's to Kubuntu and my Server from Win2k to Ubuntu Server, I am slowly learning. but well luckily there is a great community to guide me. :-)
I'm running Ubuntu Server with lm-sensors installed.
For Cacti I would like to extract the raw temperature and Fan values without the fancy formatting from the sensors command.
So after a lot of searching and testing in /dev, /proc and /sys, I finally found that they are stored in /sys/bus/i2c/devices/9191-0290/
The backtics makes the stdout of 'cat' seem to be a comandline component, which can be assigned to a variable. It also groups the commandline into two operations.
Location: Montpellier, France, Europe, World, Solar System
Distribution: Debian Sarge, Fedora core 5 (i386 and x86_64)
Posts: 262
Rep:
This line in your script:
Code:
a=cat /sys/bus/i2c/devices/9191-0290/temp1_input
basically says: put the string 'cat' in variable a and then try to run the command /sys/bus/i2c/devices/9191-0290/temp1_input. To say you want to put the result of the full command "cat /sys/bus/i2c/devices/9191-0290/temp1_input" into the variable, you need to surround it by backticks like that:
The perl example did work (presumably) but perl doesn't print a newline by default, so your prompt overwrote the output:
Code:
perl -ne 'print $_ / 1000.0, "\n"' ...
should work.
The shell can also do arithmetic itself with $(( ... )). Unfortunately bash is no use in this case as it can only handle integer arithmetic but more powerful shells like zsh can do floating point too, e.g.
Note the use of $(<...), which is equivalent to 'cat ...' except that the shell reads the file itself rather the spawning an instance of cat, so it is somewhat more efficient.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.