html/sysinfo_juerd.pl


   1 
   2 # Those <censored> mIRC'ers have all those irritating system info "remotes" to
   3 # brag about their system.
   4 # Now, it's up to Irssi users to brag about their pentium 75's and 2 Gio harddisks.
   5 # :)
   6 
   7 # Differences to Juerd-only-version:
   8 # -YASFU units (Mio, Gio) - http://snull.cjb.net/?yasfu
   9 # -Free memory and free swap are displayed (previously only total swap/mem)
  10 # -Reorganized and tuned output
  11 # -Displays length of your virtual penis (this is quite tricky, so you might want to disable it by commenting)
  12 # -Doesn't display info on nfs/smbfs/none-type mounts (edit script if you want those)
  13 
  14 # Vpenis is not 100% compatible with Cras' vpenis.sh - I have fixed some bugs:
  15 # -More network filesystems excluded (originally only NFS was excluded)
  16 # -Total amount of memory counts (not the used amount, as before)
  17 
  18 # Changelog 2.10 -> 2.20: memory/swap info is displayed now (it was broken previously) and code is properly indented
  19 
  20 $VERSION = "2.20";
  21 %IRSSI = (
  22 	  authors     => "Juerd, Tronic",
  23 	  contact     => "trn\@iki.fi",
  24 	  name        => "SysinfoPlus",
  25 	  description => "Linux system information (with vPenis and other stuff)",
  26 	  license     => "Public Domain",
  27 	  url         => "http://juerd.nl/irssi/",
  28 	  changed     => "Mon Nov 04 15:17:30 EET 2002"
  29 	  );
  30 
  31 BEGIN{
  32     use vars '$console';
  33     eval q{
  34 		use Irssi;
  35 		Irssi::version();
  36         };
  37     $console = !!$@;
  38 }
  39 
  40 use strict;
  41 
  42 # Tronic has no time for maintaining this and Juerd hates braces, so it might be better
  43 # not to expect any new versions ...
  44 
  45 sub sysinfo{
  46     # This should really need indenting, but I'm kinda lazy.
  47     
  48     my (@uname, $ret, @pci, $usr, $avg, $up, $vpenis);
  49     
  50     @uname = (split ' ', `uname -a`)[0..2];
  51     
  52     $ret = "Host '@uname[1]', running @uname[0] @uname[2] - ";
  53     
  54     open FOO, '/proc/cpuinfo';
  55     while (<FOO>){
  56 	/^processor\s*:\s*(\d+)/         ? $ret .= "Cpu$1: "
  57 	  : /^model name\s*:\s*(\w+[ A-Za-z]*)/ ? do { my $t = $1; $t =~ s/\s+$//; $ret .= "$t " }
  58 	: /^cpu MHz\s*:\s*([\.\d]+)/       ? $ret .= int(.5+$1) . ' MHz '
  59 	  : undef;
  60     }
  61     close FOO;
  62     $ret =~ s/( ?)$/;$1/;
  63     open FOO, '/proc/pci';
  64     while (<FOO>){
  65 	/^\s*(?:multimedia )?(.*?)( storage| compatible)? controller/i and push @pci, $1;
  66     }
  67     close FOO;
  68     $ret .= 'PCI: ' . join(',', map ucfirst, @pci) . '; ' if @pci;
  69     if (`uptime` =~ /^.*?up\s*(.*?),\s*(\d+) users?,.*: ([\d\.]+)/){
  70 	($usr, $avg) = ($2, $3);
  71 	($up = $1) =~ s/\s*days?,\s*|\+/d+/;
  72 	$ret .= "Up: $up; Users: $usr; Load: $avg; ";
  73     }
  74     
  75     # Free space
  76     $ret .= "Free:";
  77     if (`free` =~ /Mem:\s*(\d*)\s*\d*\s*(\d*)/) { $ret .= " [Mem: " . int(.5 + $2/2**10) . "/" . int(.5 + $1/2**10) . " Mio]"; } # For compatibility: replace $1 with $2
  78     if (`free` =~ /Swap:\s*(\d*)\s*\d*\s*(\d*)/) { $ret .= " [Swap: " . int(.5 + $2/2**10) . "/" . int(.5 + $1/2**10) . " Mio]"; } # For compatibility: replace $1 with $2
  79 
  80     for (`df -m -x nfs -x smbfs -x none`) {
  81 	/^\/\S*\s*(\S*)\s*\S*\s*(\S*)\s*\S*\s*(\S*)/ and $ret .= " [$3: $2/$1 Mio]";
  82     }
  83     $ret .= ";";
  84     
  85     # Vpenis (derived from vpenis.sh)
  86     $vpenis = 70;
  87     if (`cat /proc/uptime` =~ /(\d*)/) { $vpenis += int($1/3600/24)/10; }
  88     if (`cat /proc/cpuinfo` =~ /MHz\s*:\s*(\S*)/) { $vpenis += $1/30; }
  89     if (`free` =~ /Mem:\s*(\d*)\s*(\d*)/) { $vpenis += $1/1024/3; } # For compatibility: replace $1 with $2
  90     for (`df -P -k -x nfs -x smbfs -x none|grep -v blocks`) { # For compatibility: remove -x smbfs -x none
  91 	if (/^\S*\s*(\S*)/) { $usr = $1; $vpenis += ((/^\/dev\/(scsi|sd)/) ? 2*$usr : $usr)/1024/50/15; }
  92     }
  93     $ret .= " Vpenis: " . int($vpenis)/10 . " cm;";
  94     
  95     if ($console){
  96 	print "$ret\n";
  97     }else{
  98 	Irssi::active_win->command("/say $ret");
  99     }
 100 } #end of sub
 101   
 102 if ($console){
 103     sysinfo();
 104 }else{
 105     Irssi::command_bind('sysinfo', 'sysinfo')
 106 }