From: Adrian Sevcenco <Adrian.Sevcenco@cern.ch>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] non-interactive sensors-detect
Date: Mon, 22 Oct 2012 13:23:19 +0000 [thread overview]
Message-ID: <508548C7.8030203@cern.ch> (raw)
In-Reply-To: <507BD5C2.8050506@cern.ch>
[-- Attachment #1.1: Type: text/plain, Size: 8474 bytes --]
On 10/22/2012 03:47 PM, Jean Delvare wrote:
> On Mon, 15 Oct 2012 12:22:10 +0300, Adrian Sevcenco wrote:
>> Hi! Is there a way to run sensors-detect in a non-interactive way?
>> I try to enable lm_sensors on a cluster and i find no way to do it..
>> Is is possible to add switches like -y (yes all) or -d (default all) to
>> sensors detect?
>
> Proposal below. It doesn't feel too safe as random I2C adapters may
> still get probed. But it's definitely better that people trying to get
> a non-interactive sensors-detect using "yes |".
Great, thanks!
is this applied to trunk or should i apply the patch to a fresh trunk
and rebuild?
Thanks a lot!
Adrian
> sensors-detect: Introduce automatic mode
>
> Add option --auto to sensors-detect, for non-interactive use. Default
> answer is assumed to every question.
> ---
> prog/detect/sensors-detect | 61 ++++++++++++++++++++++++++++++------------
> prog/detect/sensors-detect.8 | 13 +++++++-
> 2 files changed, 55 insertions(+), 19 deletions(-)
>
> --- lm-sensors.orig/prog/detect/sensors-detect 2012-10-22 14:17:14.000000000 +0200
> +++ lm-sensors/prog/detect/sensors-detect 2012-10-22 14:37:48.115614548 +0200
> @@ -39,7 +39,8 @@ foreach ('/usr/sbin', '/usr/local/sbin',
>
> use constant NO_CACHE => 1;
> use vars qw(@pci_adapters @chip_ids @ipmi_ifs @non_hwmon_chip_ids
> - $i2c_addresses_to_scan $revision @i2c_byte_cache);
> + $i2c_addresses_to_scan $revision @i2c_byte_cache
> + $opt_auto);
>
> $revision = '$Revision: 6057 $ ($Date: 2012-06-01 17:47:27 +0200 (ven. 01 juin 2012) $)';
> $revision =~ s/\$\w+: (.*?) \$/$1/g;
> @@ -2457,6 +2458,16 @@ sub overlay_hash
> return %result;
> }
>
> +# Read answer from stdin or accept default answer automatically
> +sub read_answer
> +{
> + if ($opt_auto) {
> + print "\n";
> + return "";
> + }
> + return <STDIN>;
> +}
> +
> ###################
> # I/O PORT ACCESS #
> ###################
> @@ -3667,7 +3678,7 @@ sub scan_i2c_adapter
> "Do you want to scan it? (\%s/selectively): ",
> $default ? "YES/no" : "yes/NO";
>
> - $input = <STDIN>;
> + $input = read_answer();
> if ($input =~ /^\s*n/i
> || (!$default && $input !~ /^\s*[ys]/i)) {
> print "\n";
> @@ -3678,7 +3689,7 @@ sub scan_i2c_adapter
> print "Please enter one or more addresses not to scan. Separate them with commas.\n",
> "You can specify a range by using dashes. Example: 0x58-0x5f,0x69.\n",
> "Addresses: ";
> - $input = <STDIN>;
> + $input = read_answer();
> chomp($input);
> @not_to_scan = parse_not_to_scan(0x03, 0x77, $input);
> } elsif (($class & 0xff00) == 0x0300) {
> @@ -6632,7 +6643,7 @@ sub write_config
> printf "Do you want to \%s /etc/modprobe.d/lm_sensors.conf? (\%s): ",
> (-e '/etc/modprobe.d/lm_sensors.conf' ? 'overwrite' : 'generate'),
> ($have_modprobe_d ? 'YES/no' : 'yes/NO');
> - $_ = <STDIN>;
> + $_ = read_answer();
> if (($have_modprobe_d and not m/^\s*n/i) or m/^\s*y/i) {
> unless ($have_modprobe_d) {
> mkdir('/etc/modprobe.d', 0777)
> @@ -6656,7 +6667,7 @@ sub write_config
> printf "Do you want to \%s /etc/sysconfig/lm_sensors? (\%s): ",
> (-e '/etc/sysconfig/lm_sensors' ? 'overwrite' : 'generate'),
> ($have_sysconfig ? 'YES/no' : 'yes/NO');
> - $_ = <STDIN>;
> + $_ = read_answer();
> if (($have_sysconfig and not m/^\s*n/i) or m/^\s*y/i) {
> unless ($have_sysconfig) {
> mkdir('/etc/sysconfig', 0777)
> @@ -6757,6 +6768,10 @@ sub main
> exit 0;
> }
>
> + if (defined $ARGV[0] && $ARGV[0] eq "--auto") {
> + $opt_auto = 1;
> + }
> +
> # We won't go very far if not root
> unless ($> == 0) {
> print "You need to be root to run this script.\n";
> @@ -6784,14 +6799,21 @@ sub main
> initialize_dmi_data();
> print_dmi_summary();
> print "\n";
> - print "This program will help you determine which kernel modules you need\n",
> - "to load to use lm_sensors most effectively. It is generally safe\n",
> - "and recommended to accept the default answers to all questions,\n",
> - "unless you know what you're doing.\n\n";
> +
> + if ($opt_auto) {
> + print "Running in automatic mode, default answers to all questions\n",
> + "are assumed.\n\n";
> + } else {
> + print "This program will help you determine which kernel modules you need\n",
> + "to load to use lm_sensors most effectively. It is generally safe\n",
> + "and recommended to accept the default answers to all questions,\n",
> + "unless you know what you're doing.\n\n";
> + }
>
> print "Some south bridges, CPUs or memory controllers contain embedded sensors.\n".
> "Do you want to scan for them? This is totally safe. (YES/no): ";
> - unless (<STDIN> =~ /^\s*n/i) {
> + $input = read_answer();
> + unless ($input =~ /^\s*n/i) {
> # Load the cpuid driver if needed
> unless (-e "$sysfs_root/class/cpuid") {
> load_module("cpuid");
> @@ -6813,7 +6835,8 @@ sub main
> print "Some Super I/O chips contain embedded sensors. We have to write to\n".
> "standard I/O ports to probe them. This is usually safe.\n";
> print "Do you want to scan for Super I/O sensors? (YES/no): ";
> - unless (<STDIN> =~ /^\s*n/i) {
> + $input = read_answer();
> + unless ($input =~ /^\s*n/i) {
> initialize_ioports();
> $superio_features |= scan_superio(0x2e, 0x2f);
> $superio_features |= scan_superio(0x4e, 0x4f);
> @@ -6828,7 +6851,8 @@ sub main
> "there, we have to read from arbitrary I/O ports to probe for such\n".
> "interfaces. This is normally safe. Do you want to scan for IPMI\n".
> "interfaces? (YES/no): ";
> - unless (<STDIN> =~ /^\s*n/i) {
> + $input = read_answer();
> + unless ($input =~ /^\s*n/i) {
> if (!ipmi_from_smbios()) {
> initialize_ioports();
> scan_isa_bus(\@ipmi_ifs);
> @@ -6843,7 +6867,7 @@ sub main
> "safe though. Yes, you do have ISA I/O ports even if you do not have any\n".
> "ISA slots! Do you want to scan the ISA I/O ports? (\%s): ",
> $superio_features ? "yes/NO" : "YES/no";
> - $input = <STDIN>;
> + $input = read_answer();
> unless ($input =~ /^\s*n/i
> || ($superio_features && $input !~ /^\s*y/i)) {
> initialize_ioports();
> @@ -6859,7 +6883,8 @@ sub main
> "on some systems.\n".
> "Do you want to probe the I2C/SMBus adapters now? (YES/no): ";
>
> - unless (<STDIN> =~ /^\s*n/i) {
> + $input = read_answer();
> + unless ($input =~ /^\s*n/i) {
> adapter_pci_detection();
> load_module("i2c-dev") unless -e "$sysfs_root/class/i2c-dev";
> initialize_i2c_adapters_list();
> @@ -6895,9 +6920,11 @@ sub main
> exit;
> }
>
> - print "Now follows a summary of the probes I have just done.\n".
> - "Just press ENTER to continue: ";
> - <STDIN>;
> + print "\nNow follows a summary of the probes I have just done.\n";
> + unless ($opt_auto) {
> + print "Just press ENTER to continue: ";
> + <STDIN>;
> + }
>
> initialize_hwmon_autoloaded();
> foreach my $driver (keys %chips_detected) {
> --- lm-sensors.orig/prog/detect/sensors-detect.8 2008-12-03 16:13:14.000000000 +0100
> +++ lm-sensors/prog/detect/sensors-detect.8 2012-10-22 14:45:02.810749684 +0200
> @@ -1,9 +1,11 @@
> -.TH SENSORS-DETECT 8 "December 2008" "lm-sensors 3"
> +.TH SENSORS-DETECT 8 "October 2012" "lm-sensors 3"
> .SH NAME
> sensors-detect \- detect hardware monitoring chips
>
> .SH SYNOPSIS
> -.B sensors-detect
> +.B sensors-detect [
> +.I --auto
> +.B ]
>
> .SH DESCRIPTION
> sensors-detect is an interactive program that will walk you through the
> @@ -30,6 +32,13 @@ his/her wish. This can be useful if a gi
> hardware monitoring chip. Some vendors are known to do this, most notably
> Asus and Tyan.
>
> +.SH OPTIONS
> +.IP "--auto"
> +Run in automatic, non-interactive mode. Assume default answers to all
> +questions. Note that this isn't necessarily safe as the internal logic may
> +lead to potentially dangerous probes being attempted. See the WARNING section
> +below.
> +
> .SH WARNING
> sensors-detect needs to access the hardware for most of the chip detections.
> By definition, it doesn't know which chips are there before it manages to
>
[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 1997 bytes --]
[-- Attachment #2: Type: text/plain, Size: 153 bytes --]
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
next prev parent reply other threads:[~2012-10-22 13:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-15 9:22 [lm-sensors] non-interactive sensors-detect Adrian Sevcenco
2012-10-15 14:12 ` Guenter Roeck
2012-10-22 12:47 ` Jean Delvare
2012-10-22 13:23 ` Adrian Sevcenco [this message]
2012-10-22 13:33 ` Jean Delvare
2012-10-22 13:52 ` Guenter Roeck
2012-10-30 17:08 ` Jean Delvare
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=508548C7.8030203@cern.ch \
--to=adrian.sevcenco@cern.ch \
--cc=lm-sensors@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.