LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Perl script to capture system info? (http://www.linuxquestions.org/questions/programming-9/perl-script-to-capture-system-info-719826/)

Zmyrgel 04-17-2009 07:51 AM

Perl script to capture system info?
 
I'm thinking on writing a perl script to catch system info such as processor frequency, disk usage, battery state etc.
Is there any perl library to help achieve this in portable way (Linux/BSD)?

Need stuff to populate my dzen statusbar and to learn perl at the same time.

I could always try to achieve it by using system commands but I'd guess it wouldn't be quite portable approach to this.
Any hints are welcome.

bigearsbilly 04-17-2009 08:33 AM

after a quick search through my FreeBSD ports I found:

p5-Unix-Statgrab
p5-Unix-Processors

any use?

Zmyrgel 04-17-2009 09:38 AM

They seem to be pretty much what I'm after. Thanks for pointing them out.

ghostdog74 04-17-2009 11:42 AM

another one.
Code:

use Data::Dumper;
use Linux::SysInfo qw/sysinfo/;
my $si = sysinfo;
print Dumper($si);


Zmyrgel 04-18-2009 03:30 AM

Quote:

Originally Posted by ghostdog74 (Post 3512365)
another one.
Code:

use Data::Dumper;
use Linux::SysInfo qw/sysinfo/;
my $si = sysinfo;
print Dumper($si);


I doubt that this will work on my OpenBSD laptop, thats why I asked portable ways to do this.

Currently trying to find portable way to get battery info but no luck so far.
I'm having some grand idea to write the C code to get battery info to the libstatgrab and update the perl bindings but that will take some time with my 'aw3some' l33t hax0r skillz' :)
Meanwhile some other way to do this is needed. Probably the quickest way would be to test OS and then parse /proc/acpi/battery or apm output.

But could you help debug a small issue with my mail count info.
I'm trying to connect to remote server ( or localhost) running dovecot that serves my maildirs through IMAP. It doesn't allow plaintext authentication so I need the SSL stuff.

Code:

use Mail::IMAPClient;
use IO::Socket::SSL;
# Doesn't work yet
sub new_msgs {
    my $imap = Mail::IMAPClient->new
        ( User    => $username,
          Password => $pass,
          Socket  => IO::Socket::SSL->new
          (  Proto    => 'tcp',
            PeerAddr => $server,
            PeerPort => 993,
          ),
        );
    #$imap->connect or die "Could not connect: $@\n";
    my $msgcount = $imap->message_count($mail_folder); # line 75
    defined($msgcount) or die "Could not message_count: $@\n";
    return $msgcount;

it gives following message:
Code:

Not connected at status.pl line 75
Error sending '1 STATUS INBOX (MESSAGES)' to IMAP: Connection refused at status.pl line 75
Could not message_count: Error sending '1 STATUS INBOX (MESSAGES)' to IMAP: Connection refused

I can't figure out whats the case is here. First line states that it is not connected but the last line states that the connection was refused. I'd think it can't be both.

If I uncomment the 'connect' line it gives following
Code:

Could not connect: Unable to connect to : Invalid argument
Any suggestions how to get this working?

Edit: ha, got it working after googling for this a bit and found this.


All times are GMT -5. The time now is 03:37 AM.