LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Can Somebody Explain: lm-sensors and sensors-detect... (http://www.linuxquestions.org/questions/linux-newbie-8/can-somebody-explain-lm-sensors-and-sensors-detect-934453/)

WeBMartians 03-14-2012 02:30 PM

Can Somebody Explain: lm-sensors and sensors-detect...
 
Odd behavior when invoking/launching sensors-detect from within a BASH script...
Code:

/sbin/modprobe w83627ehf
/usr/sbin/sensors-detect < /usr/bin/yes YES

The sensors-detect script (Perl) seems to treat the first response as NO; all of the others are YES.

The host environment is 2.6.18-164.el5PAE (CentOS).

From the console, the behavior is nominal:
  • Console
    Code:

    /usr/sbin/sensors-detect
    and, then, answer, manually ... you get the expected results
  • Automation
    Code:

    /usr/sbin/sensors-detect < /usr/bin/yes YES
    produces the expected results

...but code the automated code in a BASH script and sensors-detect seems to ignore the first prompt result (treating it as a NO)!

I made a modified copy of sensors-detect (sensors-detectYES) that treats the first prompt result as 1 (true, YES, ... whatever) and all seems OK ... it's ugly but it works.

Does anybody have an explanation for what's happening?

rknichols 03-14-2012 09:47 PM

Quote:

Originally Posted by WeBMartians (Post 4626758)
Odd behavior when invoking/launching sensors-detect from within a BASH script...
Code:

/sbin/modprobe w83627ehf
/usr/sbin/sensors-detect < /usr/bin/yes YES

The sensors-detect script (Perl) seems to treat the first response as NO; all of the others are YES.

With that syntax you are not executing the /usr/bin/yes program. You are taking the content of the /usr/bin/yes binary file and sending that to the stdin of sensors-detect. I wouldn't care to guess about how sensors-detect will parse that gibberish. Try either of these:
Code:

/usr/bin/yes YES | /usr/sbin/sensors-detect

/usr/sbin/sensors-detect <(/usr/bin/yes YES)    # This is wrong, sorry


WeBMartians 03-15-2012 10:53 AM

Batting 500
 
The former approach ("pipe")
Code:

#!/bin/bash
/sbin/modprobe w83627ehf
/usr/bin/yes YES | /usr/sbin/sensors-detect

seems to work.

The latter
Code:

#!/bin/bash
/sbin/modprobe w83627ehf
/usr/sbin/sensors-detect <(/usr/bin/yes YES)

just hangs ... even when executed, from the console, outside of a script.

Since the pipe technique works (and I understand it ... I swear I did try it that way, earlier ... sigh), that's what I'm going with ("Ship it!").

As to why the latter does not work, I haven't a clue: a learning experience for the future.

Thank you for your advice and help! I very much appreciate it.

rknichols 03-16-2012 12:19 AM

Quote:

Originally Posted by WeBMartians (Post 4627489)
The latter
Code:

#!/bin/bash
/sbin/modprobe w83627ehf
/usr/sbin/sensors-detect <(/usr/bin/yes YES)

just hangs ... even when executed, from the console, outside of a script.

Since the pipe technique works (and I understand it ... I swear I did try it that way, earlier ... sigh), that's what I'm going with ("Ship it!").

As to why the latter does not work, I haven't a clue: a learning experience for the future.

That would be because I was posting in haste and made a mistake. It's just plain wrong. (It would work for programs like cat, that read either from stdin or from a filename passed as an argument. sensors-detect does not do the latter.)


All times are GMT -5. The time now is 08:00 PM.