#!/usr/bin/perl -w # RitBits is Jen's first script... first of anything like this actually. So expect bugs. # Official Page: http://caffeinated-dreams.net/2005/06/28/rit-bits-perl-script-for-x-chat/ # Version: 0.3.2 (June 30th, 2005) # Do whatever to this script. I don't care. # ################ Credits ################ # Gamakichi for being awesome, hardrive/cpu/netstat/uptime/new desktop display improvement and perl support. # Neovanglist for FreeBSD-fu. # Good folks in #Xion on IRC for support and allowing us to spam our testing. That's probably only because they were sleeping though. =) # # # TODO RAM display improvement, temperature sensors(?), xmms/beep media player/amarok support (??!) # # Only edit hardrive information ($hdd2), the part that may need editing is labled. Otherwise do not touch below this unless you know what you're doing. :P IRC::register("RitBits", "0.5", "", ""); IRC::print "\cC2\cBRitBits loaded!\003 Commands are: /ritbits /client /gfx /os /desktop /cpu /sound /netstat /disk /uptime /date"; IRC::add_command_handler("ritbits", "ritbits"); IRC::add_command_handler("gfx", "gfx"); IRC::add_command_handler("os", "os"); IRC::add_command_handler("client", "client"); IRC::add_command_handler("desktop", "desktop"); IRC::add_command_handler("cpu", "cpu"); IRC::add_command_handler("sound", "sound"); IRC::add_command_handler("netstat", "netstat"); IRC::add_command_handler("disk", "disk"); IRC::add_command_handler("uptime", "uptime"); IRC::add_command_handler("date", "date"); # About sub ritbits { IRC::command("\cC2\cBRitBits\cB\003 - A n00b script by Jen for X-Chat, version 0.5 (\cBhttp://caffeinated-dreams.net\cB)"); return 1; } # Video card, resolution sub gfx { $xorg = `xdpyinfo | grep X.Org"."version`; chomp ($xorg); $res = `xdpyinfo | grep dimensions | awk '{print \$2}'`; chomp ($res); $vid = `sysctl dev.drm.0.\%desc | cut -d : -f 2`; chomp ($vid); @bits = `xwininfo -root`; foreach (@bits) { if (/^ +?Depth: (.+)/i) {$bits = $1;} } IRC::command("( \cC2\cBGraphics\cB\003 ) \cB $vid \cB,\cB $xorg \cB ( \cC2\cBResolution\cB\003 ) \cB $res \cB ( \cC2\cBBits\cB\003 ) \cB $bits \cB"); return 1; } # Operating System sub os { $os =`uname -srm`; chomp ($os); IRC::command("( \cC2\cBOperating System\cB\003 ) \cB $os \cB"); return 1; } # Desktop Environment sub desktop { system "ps -a | grep startkde > .a1"; system "ps -a | grep gnome-session > .a2"; system "ps -a | grep fluxbox > .a3"; system "ps -a | grep enlightenment > .a4"; system "ps -a | grep xfce4 > .a5"; $desktop = `kde-config -version | grep KDE` if -s ".a1"; $desktop = `gnome-config --version | grep gnome` if -s ".a2"; $desktop = `fluxbox -version | cut -d" " -f1-2` if -s ".a3"; $desktop = `enlightenment -version | cut -d" " -f1,3` if -s ".a4"; $desktop = `xfwm4 --version | grep Xfce | cut -c10-50 | cut -d" " -f5,6` if -s ".a5"; chomp ($desktop); IRC::command("( \cC2\cBDesktop Environment\cB\003 ) \cB $desktop \cB"); system "rm .a*"; return 1; } # CPU sub cpu { $model = `sysctl hw.model | cut -d: -f2`; chomp ($model); $freq = `dmesg | grep CPU: | cut -d" " -f6 | cut -c2-8`; chomp ($freq); IRC::command("( \cC2\cBCPU\cB\003 ) \cB $model \cB ( \cC2\cBFrequency\cB\003 ) \cB $freq \cB MHz"); return 1; } # Hardrives, can support multiple disks. # Uncomment the lines below for a second disk. sub disk { open(AWKU, ">.awkU"); open(AWKT, ">.awkT"); print AWKU '{ print $3 }'; print AWKT '{ print $2 }'; $A = `df -h | grep -m1 /usr | awk -f .awkU`; $B = `df -h | grep -m1 /usr | awk -f .awkT`; $C = `df -h | grep -m1 /usr2 | awk -f .awkU`; $D = `df -h | grep -m1 /usr2 | awk -f .awkT`; chomp ($A); chomp ($B); chomp ($C); chomp ($D); IRC::command("( \cC2\cBHardrives\cB\003 ) /usr: \cBUsed: ".$A." \\ Total: ".$B." \cB/usr2: \cBUsed: ".$C." \\ Total: ".$D.""); close AWKU; close AWKT; system "rm .awk*"; return 1; } # Soundcard sub sound { $sound = `sysctl dev.pcm.0.\%desc | cut -d: -f2`; chomp ($sound); IRC::command("( \cC2\cBSoundcard\cB\003 ) \cB $sound \cB"); return 1; } # Network statistic, shows KB down and up. sub netstat { open(AWKFILEI, ">.awkI"); open(AWKFILEO, ">.awkO"); print AWKFILEI '{ print $7 }'; print AWKFILEO '{ print $10 }'; $Idata = `netstat -bi | grep Link#1 | awk -f .awkI`; $Odata = `netstat -bi | grep Link#1 | awk -f .awkO`; chomp ($Idata); chomp ($Odata); $Idata /= 1024 ; $Odata /= 1024 ; $In = sprintf("%.2f", $Idata); $Out = sprintf("%.2f", $Odata); IRC::command("( \cC2\cBNetwork Statistics\cB\003 ) \cB Down\: $In KB \\ Up\: $Out KB \cB"); close AWKFILEI; close AWKFILEO; system "rm .awk*"; return 1; } # Uptime sub uptime { $up = `uptime`; open(AWK1, ">.t1"); open(AWK2, ">.t2"); open(AWK3, ">.t3"); open(AWK4, ">.t4"); open(AWK5, ">.t5"); open(AWK6, ">.t6"); print AWK1 '{ print $1 }'; print AWK2 '{ print $2 }'; print AWK3 '{ print $3 }'; print AWK4 '{ print $4 }'; print AWK5 '{ print $5 }'; print AWK6 '{ print $6 }'; $when1 = `uptime | awk -f .t6`; $when2 = `uptime | awk -f .t5`; $when3 = `uptime | awk -f .t3`; $when4 = `uptime | awk -f .t4`; if ( length($up) >= 66 ) { if ( $when1 =~ /sec/ ) { $timeD = `uptime | awk -f .t3`; $timeS = `uptime | awk -f .t5`; chomp($timeD); chomp($timeS); IRC::command("( \cC2\cBCurrent Uptime\cB\003 )\cB $timeD \cB\cC2Days\cB\003 $timeS \cB\cC2Seconds"); } elsif ( $when1 =~ /min/ ) { $timeD = `uptime | awk -f .t3`; $timeM = `uptime | awk -f .t5`; chomp($timeD); chomp($timeM); IRC::command("( \cC2\cBCurrent Uptime\cB\003 )\cB $timeD \cB\cC2Days\cB\003 $timeM \cB\cC2Minutes"); } elsif ( $when2 =~ /:/ ) { $timeH = `uptime | awk -f .t5 | awk -F: -f .t1`; $timeM = `uptime | awk -f .t5 | awk -F: -f .t2 | cut -c1-2`; $timeD = `uptime | awk -f .t3`; chomp($timeD); chomp($timeH); chomp($timeM); IRC::command("( \cC2\cBCurrent Uptime\cB\003 )\cB $timeD \cB\cC2Days\cB\003 $timeH \cB\cC2Hours\cB\003 $timeM \cB\cC2Minutes"); }; } elsif ( $when3 =~ /:/ ) { $timeH = `uptime | awk -f .t3 | awk -F: -f .t1`; $timeM = `uptime | awk -f .t3 | awk -F: -f .t2 | cut -c1-2`; chomp($timeH); chomp($timeM); IRC::command("( \cC2\cBCurrent Uptime\cB\003 )\cB $timeH \cB\cC2Hours\cB\003 $timeM \cB\cC2Minutes"); } elsif ( $when4 =~ /min/ ) { $timeM = `uptime | awk -f .t3`; chomp($timeM); IRC::command("( \cC2\cBCurrent Uptime\cB\003 )\cB $timeM \cB\cC2Minutes"); }; close AWK1; close AWK2; close AWK3; close AWK4; close AWK5; close AWK6; system "rm .t*"; return 1; } # X-Chat version sub client { $client = IRC::get_info(0); chomp ($client); IRC::command("( \cC2\cBIRC Client\cB\003 ) \cB X-Chat $client \cB"); return 1; } #Date and Time sub date { open(D1, ">.d1"); open(D2, ">.d2"); open(D3, ">.d3"); open(D4, ">.d4"); open(D6, ">.d6"); print D1 '{ print $1 }'; print D2 '{ print $2 }'; print D3 '{ print $3 }'; print D4 '{ print $4 }'; print D6 '{ print $6 }'; $_day = `date | awk -f .d1`; chomp($_day); $_mon = `date | awk -f .d2`; chomp($_mon); SWITCH: for ($_day) { /Sun/ && do { $day = "Sunday"; }; /Mon/ && do { $day = "Monday"; }; /Tue/ && do { $day = "Tuesday"; }; /Wed/ && do { $day = "Wednesday"; }; /Thu/ && do { $day = "Thursday"; }; /Fri/ && do { $day = "Friday"; }; /Sat/ && do { $day = "Saturday"; }; }; SWITCH: for ($_mon) { /Jan/ && do { $mon = "January"; }; /Feb/ && do { $mon = "February"; }; /Mar/ && do { $mon = "March"; }; /Apr/ && do { $mon = "April"; }; /May/ && do { $mon = "May"; }; /Jun/ && do { $mon = "June"; }; /Jul/ && do { $mon = "July"; }; /Aug/ && do { $mon = "August"; }; /Sep/ && do { $mon = "September"; }; /Oct/ && do { $mon = "October"; }; /Nov/ && do { $mon = "November"; }; /Dec/ && do { $mon = "December"; }; }; chomp($mon); $a = `date | awk -f .d3`; chomp($a); $b = `date | awk -f .d6`; chomp($b); $date = $mon." ".$a.", ".$b; $_hr = `date | awk -f .d4 | cut -d: -f1`; chomp($_hr); $_mn = `date | awk -f .d4 | cut -d: -f2`; chomp($_mn); if ( $_hr > 12 ) { $_hr -= 12; $time = $_hr.":".$_mn." PM"; } elsif ( $_hr == 12 ) { $time = $_hr.":".$_mn." PM"; } elsif ( $_hr < 10 ) { $_hr = `date | awk -f .d4 | cut -d: -f1 | cut -c2`; chomp($_hr); $time = $_hr.":".$_mn." AM"; }; chomp($day); chomp($date); chomp($time); IRC::command("( \cC2\cBTime\cB\003 ) $time ( \cC2\cBDay\cB\003 ) $day ( \cC2\cBDate\cB\003 ) $date"); close D1; close D2; close D3; close D4; close D6; system "rm .d*"; return 1; }