All pastes #402877 Raw Edit

QwErTz

public text v1 · immutable
·published 2007-03-20 01:26 UTC
rendered paste body
use strict;
use warnings;
use vars qw($VERSION %IRSSI);

use Irssi;
$VERSION = '1.00';
%IRSSI = (
	authors		=> 'QwErTz',
	contact		=> 'qwertz@videotron.ca',
	name		=> 'Sysinfo OS X',
);

use Irssi qw(command_bind signal_add);

sub subSysinfo {
	
	## Global Variables Define ##
	my ($data, $server, $witem) = @_;
	
	## Long Variables Define ##
	my ($cpu_type_long, $kernel_release_long, $uptime_long, $mem_total_long, $mem_used_long, $disk_long) = @_;
	
	## Counter Variables
	my ($disk_total_counter, $disk_used_counter, $measurements) = @_;
	my (@measurements) = @_;
	
	## Final Variables Define ##
	my ($kernel, $kernel_release, $uptime, $cpu_type, $mem_total, $mem_used, $mem, $disk_total, $disk_used, $disk) = @_;
	
	## Long Variables ##
	$uptime_long = `uptime`;
	$cpu_type_long = `sysctl machdep.cpu.brand_string`;	
	$kernel_release_long = `sysctl kern.osrelease`;
	$mem_total_long = `sysctl hw.physmem`;
	$mem_used_long = `sysctl hw.usermem`;
	$disk_long=`df -lm | awk 'BEGIN {getline; while (getline temp > 0) { split(temp,a," "); total1 += a[4]; total2 += a[2] } }END {print total1,total2}'`;

	## Final Variables ##
	# CPU	
	$cpu_type = $cpu_type_long;
	$cpu_type = substr($cpu_type, 26);
	chomp $cpu_type;
	$cpu_type = "[CPU] " . $cpu_type;
	$cpu_type =~ s/(\s){2,}/ /;

	# Kernel
	$kernel_release = $kernel_release_long;
	$kernel_release = substr($kernel_release, 17);
	chomp $kernel_release;
	$kernel = " [Kernel] Darwin " . $kernel_release;

	# Memory Usage Used/Total
	$mem_total = $mem_total_long;
	$mem_total = substr($mem_total, 0, -1);
	$mem_total = substr($mem_total, 12);
	$mem_total = $mem_total / 1024 / 1024;
	$mem_total = sprintf("%.0f", $mem_total);
	$mem_used = $mem_used_long;
	$mem_used = substr($mem_used, 0, -1);
	$mem_used = substr($mem_used, 12);
	$mem_used = $mem_used / 1024 / 1024;
	$mem_used = sprintf("%.0f", $mem_used);
	$mem = " [RAM] " . $mem_used . "MB/" . $mem_total . "MB";	

	# Disk Usage Used/Total
	($disk_used, $disk_total) = split(/ /,$disk_long);
	@measurements = ('MB', 'GB', 'TB', 'YB');
	while($disk_used >= 1024)
	{
		$disk_used_counter++;
		$disk_used /= 1024;
	}
	while($disk_total >= 1024)
	{
		$disk_total_counter++;
		$disk_total /= 1024;
	}
	$disk_used = $disk_total - $disk_used;
	$disk_used = sprintf("%.2f",$disk_used);
	$disk_total = sprintf("%.2f",$disk_total);
	$disk = " [Disk] " . $disk_used . $measurements[$disk_used_counter] . "/" . $disk_total . $measurements[$disk_total_counter];
	
	#$disk_used = $disk_used / 1024;
	#$disk_used = sprintf("%.2f", $disk_used);
	#$disk_total = $disk_total / 1024;
	#$disk_total = sprintf("%.2f", $disk_total);
	#$disk = " [Disk] " . $disk_used . "GB/" . $disk_total . "GB";

	## Irssi Commands ##
	$server->command("/msg #tester ". $cpu_type . $kernel . $mem . $disk);	
}

command_bind sysinfo => \&subSysinfo;