Llabres Thill
2013-Feb-27 11:27 UTC
[Nut-upsuser] some help in using the package NUT in a perl script
Hello, I want use the package NUT in a script perl, i wonder how use the result of method such as BattPercent() for example. here is my code : _#!/usr/bin/perl -w_ _# server_ _use strict;_ _#use /etc/nut/dev/modules;_ _#use IO::Socket::Multicast;_ _use UPS::Nut;_ _my $message = localtime;_ _$message .=" `who` . n";_ _print "-- test : $message n";_ _my $ups = new UPS::Nut(_ _ NAME => "UPS",_ _ HOST => "localhost",_ _ PORT => 3493,_ _ USERNAME => "upsmon",_ _ PASSWORD => "pass",_ _ TIMEOUT => 30,_ _ DEBUG => 1,_ _ DEBUGOUT => "/etc/nut/dev/log/nut.log"_ _);_ _if ($ups->Status() =~ /OL/) _ _ {_ _ print "UPS : Alimentation OK !n";_ _ }_ _if ($ups->Status() =~ /OB/) _ _ {_ _ print "UPS : PB alimentation, Fonctionne sur batterie !n";_ _ }_ _print " UPS ETAT : $ups->Status() n";_ _print " UPS charge batterie : $ups->BattPercent() n";_ _print " UPS liste : $ups->ListVar() n";_ _exit(0);_ Bu i got : something like : "UPS::Nut=HASH(0x8505ad0)->BattPercent()" instead of the value expected... Could somebody help me ? Thanks for all. -- Cordialement, Thill Llabr?s - THILL.LLABRES at ETU.UNICAEN.FR M2 E-Secure -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.alioth.debian.org/pipermail/nut-upsuser/attachments/20130227/99699fde/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: smiley-frown.gif Type: image/gif Size: 340 bytes Desc: not available URL: <http://lists.alioth.debian.org/pipermail/nut-upsuser/attachments/20130227/99699fde/attachment.gif>
Charles Lepple
2013-Feb-27 12:57 UTC
[Nut-upsuser] some help in using the package NUT in a perl script
On Feb 27, 2013, at 6:27 AM, Llabres Thill wrote:> print " UPS charge batterie : $ups->BattPercent() \n";[...]> Bu i got : something like : "UPS::Nut=HASH(0x8505ad0)->BattPercent()" instead of the value expected...<smiley-frown.gif>It's been a while since I used perl, but it sounds like you might need an extra set of parentheses, or a local variable: my $batt_percent = $ups->BattPercent(); print " UPS charge batterie : $batt_percent \n"; -- Charles Lepple clepple at gmail