LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-17-2009, 07:51 AM   #1
Zmyrgel
Senior Member
 
Registered: Dec 2005
Location: Finland
Distribution: Slackware, CentOS, RHEL, OpenBSD
Posts: 1,006

Rep: Reputation: 36
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.
 
Old 04-17-2009, 08:33 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,282

Rep: Reputation: 172Reputation: 172
after a quick search through my FreeBSD ports I found:

p5-Unix-Statgrab
p5-Unix-Processors

any use?
 
Old 04-17-2009, 09:38 AM   #3
Zmyrgel
Senior Member
 
Registered: Dec 2005
Location: Finland
Distribution: Slackware, CentOS, RHEL, OpenBSD
Posts: 1,006

Original Poster
Rep: Reputation: 36
They seem to be pretty much what I'm after. Thanks for pointing them out.
 
Old 04-17-2009, 11:42 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
another one.
Code:
use Data::Dumper;
use Linux::SysInfo qw/sysinfo/;
my $si = sysinfo;
print Dumper($si);
 
Old 04-18-2009, 03:30 AM   #5
Zmyrgel
Senior Member
 
Registered: Dec 2005
Location: Finland
Distribution: Slackware, CentOS, RHEL, OpenBSD
Posts: 1,006

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by ghostdog74 View Post
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.

Last edited by Zmyrgel; 04-18-2009 at 04:06 AM. Reason: Solved issue :)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I reboot system from perl script? RavenLX Linux - General 4 11-17-2008 12:00 PM
perl script system() only execute one command knockout_artist Programming 4 11-11-2008 10:57 AM
Getting PID from a system command in Linux perl script sumbabs Linux - General 1 03-03-2005 10:38 AM
PERL script that can browse the file system... vous Programming 1 02-09-2004 01:02 PM


All times are GMT -5. The time now is 10:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration