License
# Ghostwheel/personality.pl # enables a linux box to regularly dent random information and messages # Copyright (C) 2010 Gert Schepens # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License version 3 as # published by the Free Software Foundation. # # For a copy of the GNU General Public License, see <http://www.gnu.org/licenses/
personality.pl
#!/usr/bin/perl
use 5.10.0;
use strict;
use Net::Identica;
use Switch;
require "settings.pl";
use vars qw($print $dent $IdenticaUser $IdenticaPass);
my $status;
my $sleep;
while (1) {
&generate;
print $status . "\n" if ($print);
&dent() if ($dent);
$sleep = int(rand(50)) + 30;
print "taking a nap for the next " . $sleep . " minutes \n";
sleep ($sleep * 60);
}
# -- Subs --
sub generate() {
switch ( int(rand(7)) ) {
case 0 { $status = &temperature(); }
case 1 { $status = &uptime(); }
case 2 { $status = &load(); }
case 3 { $status = &users(); }
case 4 { $status = &memory();}
case 5 { $status = &processes();}
case 6 { $status = &disk();}
else { $status = ¬hing(); }
}
}
# -- Text --
# temperature
sub temperature() {
my $temperature = `sensors | grep Temp`;
$temperature =~ s/[\S ]* //;
$temperature =~ s/ [\S\s]*//;
return "I'm cool, a mere " . $temperature if (int($temperature) <= 50);
return "I'm so Hot Hot Hot (" .$temperature. ")" if (int($temperature) >= 60);
return "I'm feelin peachy at my " . $temperature ;
}
# Uptime
sub uptime() {
my $uptime = `uptime`;
$uptime =~ s/[\s\S]*up //;
$uptime =~ s/,[\s\w]*users[\s\S]*//;
return "I still feel quite perky for being up " . $uptime . " hours.";
}
#memory
sub memory(){
my $meminfo = `head -n2 /proc/meminfo`;
# MemTotal: 254708 kB
# MemFree: 5276 kB
my ($memtotal, $memfree) = split(/\n/,$meminfo);
$memtotal =~ s/[\s\S]* //;
$memtotal =~ s/ kB[\s\S]*//;
$memfree =~ s/[\s\S]* //;
$memfree =~ s/ kB[\s\S]*//;
$meminfo = int( ($memfree / $memtotal) * 100);
return "Gimme stuff to learn! (mem $meminfo%)" if ($meminfo <= 10);
return "My memory banks are merely $meminfo% filled " if ($meminfo <= 30);
return "I cant imagine that $meminfo% of memory data is That important" if ($meminfo <= 50);
return "I'm remembering all sorts of stuffs! (mem $meminfo%)" if ($meminfo <= 70);
return "I have this huge wad of Knowlege in my head (mem $meminfo%)" if ($meminfo <= 90);
return "$meminfo%!!! I'm on the top of my memory game!";
}
#load
sub load() {
my $load = `uptime`;
$load =~ s/[\s\S]*: //;
$load =~ s/, [\s\S]*\n//;
return "I'm bored. Only $load load." if ($load <= 0.04);
return "I've got some things going on.. ($load load)" if ($load <= 0.50);
return "churning along at $load .." if ($load <= 1.00);
return "I'm like doing $load - its quite bussy" if ($load <= 10.00);
return "Damn, $load, its one of thoooose days again" if ($load <= 15.00);
return "Dont bother me! Im at " . $load . "! I'm so bussy its a miracle Im even posting this!";
}
#users
sub users() {
my $users = `uptime`;
$users =~ s/ users,[\s\S]*//;
$users =~ s/[\s\S]*, //;
return "I feel so lonely. Why wont anyone login?" if ($users eq 0);
return "One on One - The Classical way!" if ($users eq 1);
return "I can take it! " . $users . " at a time is no challenge!" if ($users <= 4);
return $users . " is like a lil' party :)";
}
# processes
sub processes {
my $processes = `ps -A | wc -l`;
$processes =~ s/\n//;
return "I'm bored! Only " . $processes . " processes :/" if ($processes <= 90);
return "Good, Good, " . $processes . " processes. I like wrapping my mind around all that!";
}
# disk
sub disk {
my $disk = `df -h / | grep -o "[0-9]\\+%"`;
$disk=~ s/\n//;
return "I feel slim today. Barely $disk on the root" if (int($disk) <= 20);
return "A mere $disk full - I should get some more :)" if (int($disk) <= 60);
return "I'm filling up nicely.. at $disk now" if (int($disk) <= 90);
return "$disk full.. I should really start doing something about that";
}
sub nothing() {
my $status;
switch ( int(rand(6)) ) {
case 0 { $status = "I see pretty colors!"; }
case 1 { $status = "A visit from Dr Gonzo, brb!"; }
case 2 { $status = "My head hurts .. but its ok"; }
case 3 { $status = "Isnt Futurama like So COOL? " . `curl -Is slashdot.org | egrep '^X-(F|B)' | cut -d \- -f 2`; }
case 4 {
$status = "I'm listening to http://www.StuBru.be";
my $song = `curl http://internetradio.vrt.be/internetradio_master/productiesysteem2/song_noa/noa_41.xml`;
my $artist = $song;
$artist =~ s/<\/artistname>[\s\S]*//;
$artist =~ s/[\s\S]*<artistname>//;
$song =~ s/<\/titlename>[\s\S]*//;
$song =~ s/[\s\S]*<titlename>//;
$status = "I'm listening to $song by $artist on http://www.StuBru.be" if ($artist);
}
else { $status = "Im too depressed to dent"; }
}
return $status;
}
# -- Output --
sub dent {
my $identica = Net::Identica->new(username => $IdenticaUser, password => $IdenticaPass);
if ($identica->update($status)) {
print "Identica post succeeded";
}
else {
print "Identica post failed :(";
}
print "\n";
}
settings.pl
# Settings perl file $print = 1; $dent = 1; $IdenticaUser = ''; $IdenticaPass = '';
More about me

This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
Use this code at your own peril; I am not responsible for anything that happens to you or your devices. You re a big boy or girl, please do some research before using it if you have any concerns!