Sigx

We are the future in the past.
It is currently Mon Jun 05, 2023 4:13 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 68 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject: WOO-HOO!!!
PostPosted: Mon Mar 15, 2004 11:46 am 
Offline

Joined: Mon Mar 15, 2004 9:09 am
Posts: 8
Location: USA
As you can see from my sig below, I managed to get SigX to show the track that XMMS is playing, along with it's current position! The Perl script is below. Note: this is a modified version of nihaopaul's hacked script for SuSE. If you want to add it to your own script, I'm posting the separate code later on in this post.

Code:

#!/usr/bin/perl

# Credits     : This script was created by and is currently maintained
#               by Victor Igumnov [lamer0@lamer0.com].
#
# Legal Info  : Copyright (C) 2003, Victor Igumnov [lamer0@lamer0.com]
#
#               This program is free software. You may redistribute it
#               and/or modify it under the terms of the GNU General
#               Public License as published by the Free Software
#               Foundation; either version 2 of the License, or
#               (at your option) any later version.
#
#               This program is distributed in the hope that it will be
#               useful, but WITHOUT ANY WARRANTY; without even the
#               implied warranty of MERCHANTABILITY or FITNESS FOR A
#               PARTICULAR PURPOSE.  See the GNU General Public License
#               for more details.
#
$|=1;
## --added code -- ##

#Config

$LIMIT            = 3000;         #// When should it change from Bytes to K ?
$MULTIPLIER   = 1024;         #// Divide by 1000 or 1024? Eternally mysterious

#$CAT = "ssh 127.0.0.1 cat /proc/net/dev";      #// Command to acces /proc/net/dev - I ssh in to get it!
#DEV = "eth0";                        #// Device to be read

$DEV = "eth0";                        #// Workstations has fewer netcards :)
$CAT = "cat /proc/net/dev";               #// A local version

$DOWNSTREAM   = 52000;               #// Max downstream in bytes;
$UPSTREAM      = 52000;               #// Max upstream in bytes;


####################################################################################
####################################################################################

#DO leave this part alone :)

$FirstTime      = time();
($FirstNetIn,  $FirstNetOut) = getNetTraffic();

sub getNetTraffic
{
   $str = `$CAT | grep $DEV`;
   ($in, $out) = ($str =~ m/^\s\s$DEV:(\S+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+) .*/);
   return ($in, $out);
}

sub display_net
{
   ($netIn, $netOut) = getNetTraffic();
#   $LastTime = time();
#   $Time   = $LastTime - $FirstTime;
#   $in      = int( ($netIn - $FirstNetIn) /$Time);
#   $out   = int( ($netOut - $FirstNetOut) /$Time);
   $in      = int( $netIn );
   $out   = int( $netOut );
   $strOut = ($out > $LIMIT)? sprintf("%.2fMB", (($out/$MULTIPLIER)/$MULTIPLIER)) : "".$out." Bytes";
   $strIn = ($in > $LIMIT)? sprintf("%.2fMb", (($in/$MULTIPLIER)/$MULTIPLIER)) : "".$in." Bytes";

   $FINALNET = "Uploaded: " . $strOut . " Downloaded: " . $strIn;

#   $FirstTime = $LastTime;
#   $FirstNetIn = $netIn;
#   $FirstNetOut = $netOut;

   return $FINALNET;
}

$imitiator = display_net;

##--end added code --##

############### START XMMS CODE ###############

sub escapecode {
  my $string = shift;

  $string =~ s/&/&/gi;
  $string =~ s/</&lt;/gi;
  $string =~ s/>/&gt;/gi;

  return $string;
}

my $XMMSFILE = "/tmp/xmms-info";

open(XMMSINFO,$XMMSFILE);

while(<XMMSINFO>) {
  chomp;
  if(/^Title: (.*)$/) {
    $XMMSSONG = escapecode($1);
  }
  if(/^Position: (.*)$/) {
    $XMMSPOSITION = escapecode($1);
  }
  if(/^Time: (.*)$/) {
    $XMMSTIME = escapecode($1);
  }
}

close XMMSINFO;
################ END XMMS CODE ################


use CGI;
use URI::URL;
use LWP::UserAgent;

#Set These
my $CPU='temp3';
my $MOBO='temp2';
my $FAN='fan2';

$MYUPTIME = `/usr/bin/uptime`;

$CPUNAME=`cat /proc/cpuinfo | grep '^model name' | head -1 | sed -e 's/^.*: //'`;
($CPUNAME)=$CPUNAME=~/^\s*(.*?)\s*$/;  # trim head/tail at same time

$CPUSPEED=`cat /proc/cpuinfo | grep 'cpu MHz' | head -1 | sed -e 's/^.*: //'`;
$BOGOMIPS=`cat /proc/cpuinfo  | grep 'bogomips' |  head -1 | sed -e 's/^.*: //'`;
$UNAME = `uname -ms`;

#--PERCENTAGE OF MEMORY FREE--#
$MEMPERCENT = `free | grep Mem | awk '{print (( \$3 -(\$6 + \$7) )/\$2)*100}'`;
chop ($MEMPERCENT);
$MEMPERCENT = sprintf('%.2f', $MEMPERCENT);


#--MEMORY FREE--#
$MEMFREE = `free | grep Mem | awk '{printf (\"%.0fg\", ( \$3 -(\$6 + \$7) )/1000)}'`;
chop ($MEMFREE);

#--TOTAL MEMORY--#
$MEMTOTAL = `free | grep Mem | awk '{printf (\"%dMb\", \$2/1000 )}'`;
chop ($MEMTOTAL);

#--SCREEN RESOLUTION--#
$RES = `xdpyinfo | grep dimensions | awk '{print \$2}'`;
chop ($RES);

#--DISKSPACE--#
$HDD = `df | awk '{ sum+=\$2/1024^2 }; END { printf (\"%dGb\", sum )}'`;
chop ($HDD);

#--DISKSPACE FREE--#
$HDDFREE = `df | awk '{ sum+=\$4/1024^2 }; END { printf (\"%dGb\", sum )}'`;
chop ($HDDFREE);

#--SCREEN RESOLUTION--#
$RES = `xdpyinfo | grep dimensions | awk '{print \$2}'`;
chop ($RES);

chop($UNAME);
chop($CPUNAME);
chop($CPUSPEED);
chop($BOGOMIPS);
$RAMLEFT=$MEMTOTAL-$MEMFREE;

$query = new CGI;
$query->import_names('webform');

my $username = "yourusername";
my $password = "yourpassword";

$DATA_2_SEND = "Uptime: $MYUPTIME *<*";
$DATA_2_SEND .= "CPU: $CPUNAME | MHZ: $CPUSPEED *<*";
#$DATA_2_SEND .= "IRC: irc.street-creed.com | NET: $FINALNET *<*";
$DATA_2_SEND .= "OS: SuSE 9.0 $UNAME *<*";
$DATA_2_SEND .= "$MEMPERCENT% Ram Used | Total RAM = $MEMTOTAL | Diskspace: $HDD Free: $HDDFREE *<*";
$DATA_2_SEND .= "Screen Res: $RES *<*";
$DATA_2_SEND .= "Currently Listening to: $XMMSSONG at $XMMSPOSITION/$XMMSTIME.";





my %form = ();

%form =('username' => $username,
   'password' => $password,
   'data'      => $DATA_2_SEND,
   'Submit'   => '');

my $ua = new LWP::UserAgent;
my $curl = url("http:");
my $req = new HTTP::Request 'POST','http://sigx.yuriy.net/update.php';
$req->content_type('application/x-www-form-urlencoded');
$req->content($curl->equery);
$curl->query_form(%form);
$req->content($curl->equery);
my $response= $ua->request($req)->as_string;



In order to make it work, you need to have the GTK+ development libraries installed, as well as the xmms-devel package. Once you have these installed, you can download the xmms-infopipe source package here:

http://www.indecentblogging.com/files/honkeykong/sigx/xmms-infopipe-1.3.tar.gz

Unpack the file into a folder, enter it from a console, and type:

Code:
./configure
make
su
(enter root password)
make install


This should install the XMMS-Infopipe plugin in your XMMS directory. Once it is installed, you will need to enable it under "General Plugins" in the XMMS config menu. After it's installed and configured, simply add this code to your script around line 22 (if you're not using the one above):

Code:

############### START XMMS CODE ###############

sub escapecode {
  my $string = shift;

  $string =~ s/&/&amp;/gi;
  $string =~ s/</&lt;/gi;
  $string =~ s/>/&gt;/gi;

  return $string;
}

my $XMMSFILE = "/tmp/xmms-info";

open(XMMSINFO,$XMMSFILE);

while(<XMMSINFO>) {
  chomp;
  if(/^Title: (.*)$/) {
    $XMMSSONG = escapecode($1);
  }
  if(/^Position: (.*)$/) {
    $XMMSPOSITION = escapecode($1);
  }
  if(/^Time: (.*)$/) {
    $XMMSTIME = escapecode($1);
  }
}

close XMMSINFO;
################ END XMMS CODE ################


and change this block:

Code:
$DATA_2_SEND="Uptime: $MYUPTIME *<*";
$DATA_2_SEND .= "CPU: $CPUNAME *<*";
$DATA_2_SEND .= "MHZ: $CPUSPEED *<*";
# $DATA_2_SEND .= "BOGOMIPS: $BOGOMIPS *<*";
$DATA_2_SEND .= "OS: $UNAME *<*$MEMPERCENT% Ram Used | Total RAM = $MEMTOTAL | $
$DATA_2_SEND .= "Diskspace: $HDD Free: $HDDFREE *<*";
# $DATA_2_SEND .= "Screen Res: $RES";
#print $DATA_2_SEND;


to look something like this:

Code:
$DATA_2_SEND="Uptime: $MYUPTIME *<*";
$DATA_2_SEND .= "CPU: $CPUNAME *<*";
$DATA_2_SEND .= "MHZ: $CPUSPEED *<*";
# $DATA_2_SEND .= "BOGOMIPS: $BOGOMIPS *<*";
$DATA_2_SEND .= "OS: $UNAME *<*$MEMPERCENT% Ram Used | Total RAM = $MEMTOTAL | $
$DATA_2_SEND .= "Diskspace: $HDD Free: $HDDFREE *<*";
# $DATA_2_SEND .= "Screen Res: $RES *<*";
$DATA_2_SEND .= "Currently Listening to: $XMMSSONG at $XMMSPOSITION/$XMMSTIME.";


After you've done this, just run the script and your sig should show your XMMS info!

Disclaimer: I make no guarantees that this will work for you. I tested it on my own machine, and it worked fine, so I'm assuming that it will work for anybody else. Also, I do not have any code for when XMMS is closed, so if the program is not open, the information will be returned as blanks. Maybe somebody with a little more XMMS/Perl experience than me (which would be pretty much anybody, as this is my first time using Perl) could fix this up.

Sorry if this info is confusing to anybody. I'm a programmer, and not a tutorial writer/guy that can simplify things. I'm sure somebody here can translate my geekspeak into something a little more understandable.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 12:49 pm 
Offline

Joined: Fri Mar 26, 2004 12:47 pm
Posts: 1
Location: Lubbock, TX
Maybe somebody can help me out with this. I was trying to get this going, and I am running Gentoo linux. I have absolutely no knowledge of perl so I have no idea what this error means. I have installed libwww-perl and curl. And I'm using this version of the script:

http://sigx.yuriy.net/dist/sigxv1.pl

When I try to run that one I get the following:

gibsonsg@loki gibsonsg $ ./sigxv1.pl
Bareword found where operator expected at ./sigxv1.pl line 88, near "$DATA_2_SEND .= "Diskspace"
(Might be a runaway multi-line "" string starting on line 87)
(Missing operator before Diskspace?)
Bareword found where operator expected at ./sigxv1.pl line 88, near "$HDD Free"
(Missing operator before Free?)
syntax error at ./sigxv1.pl line 88, near "$DATA_2_SEND .= "Diskspace"
Unterminated <> operator at ./sigxv1.pl line 88.
gibsonsg@loki gibsonsg $


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 27, 2004 6:52 pm 
Offline

Joined: Mon Mar 15, 2004 1:48 pm
Posts: 1397
Location: Los Angeles
i got that error too..

try this one. i dont get that error there.

http://sigx.yuriy.net/dist/sigx1.pl

_________________
Image

Image

Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 1:19 pm 
Offline

Joined: Tue Mar 30, 2004 1:14 pm
Posts: 1
Location: The Netherlands
Thank you for writing and updating this perl script. I have it running now on my lil' server and in my sig here as you can see :) . Even for someone who isn't that familiar with coding, ( I do know about variables and strings etc, just not who to create it all') it's easy to do.

Quite funky sucha sig :P


*edit*
why isn't my signature showing? I know how to use PHPBB but I can;t get it to work :?
*/edit*


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 4:45 pm 
Offline

Joined: Mon Mar 15, 2004 1:48 pm
Posts: 1397
Location: Los Angeles
mangamaniac wrote:
*edit*
why isn't my signature showing? I know how to use PHPBB but I can;t get it to work :?
*/edit*


try "attach signature" when you next post. or edit ur previous post and check that in.

_________________
Image

Image

Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 2:52 pm 
Offline

Joined: Thu Apr 01, 2004 2:13 pm
Posts: 5
I notice there aren't any Mac people posting. After spending some time I got it working on Mac OS X. I needed to install a bundle of Perl modules though, for libwww-perl (and prerequisites) and Mac::Glue. I used the automatic installer line sudo perl -MCPAN -e 'install "Mac::Glue"' for MacGlue (I think the installer would barf without the sudo, unless you're root). Do any Perl users know a similar shortcut for libwww-perl?

You also need to run the gluemac script to get Mac:glue to work with iTunes, which is another sudo job. (sudo ~/stupidpathtogluemac/gluemac iTunes IIRC) It didn't seem to be installed anywhere easily findable, I ended up having to search in the Finder for it.

I ended up using http://www.koch-schmidt.de/cronnix/ to get cron to actually do anything, and then that's leaving out the pipe to dev/null and 2>&1 at the end. Just putting /path/to/sigx.pl in the command bit works, assuming you've used chmod +x on it. (Although I think I know what I was doing wrong with my own attempts at using crontab.)

Quite a few of the bits of the old script needed Linux, I don't know how to get free memory, or more system information other than processor type and Darwin version (although if you edit the uname -sr to -srm 'Power Macintosh' will appear after the Darwin version). I added the iTunes code though, you can remove the lines with 'Itunes isn't doing anything' assignments to just not have any message if iTunes isn't running. The hard disk code needed an extra switch, otherwise it reported twice the hard disk space (I wish it was real.)

It's horribly hacked code, I've never used Perl before now, and I don't really know much about the Unix side of things (I'm a Mac user!) It's also based on the first version of the script. But here it is...

Code:
#!/usr/bin/perl

# Credits     : This script was created by and is currently maintained
#               by Victor Igumnov [lamer0@lamer0.com].
# Legal Info  : Copyright (C) 2003, Victor Igumnov [lamer0@lamer0.com]
#
#               This program is free software. You may redistribute it
#               and/or modify it under the terms of the GNU General
#               Public License as published by the Free Software
#               Foundation; either version 2 of the License, or
#               (at your option) any later version.
#
#               This program is distributed in the hope that it will be
#               useful, but WITHOUT ANY WARRANTY; without even the
#               implied warranty of MERCHANTABILITY or FITNESS FOR A
#               PARTICULAR PURPOSE.  See the GNU General Public License
#               for more details.
#
$|=1;

use CGI;
use URI::URL;
use LWP::UserAgent;

use Mac::Apps::Launch;
use Mac::Glue ':all';
use Socket;

my $itunes = Mac::Glue->new('iTunes');

$nowPlaying = "iTunes isn't running";

if (IsRunning($itunes->{ID})) {
    $nowPlaying = "iTunes isn't playing anything at the moment";
    my $status = $itunes->get( $itunes->prop('player state') );
    if ($status eq 'playing') {
        my $track = $itunes->prop('current track');

        my %info;
        for my $prop (qw(name artist album)) {
             $info{$prop} = $itunes->get($itunes->prop($prop => $track) );
        }
        $nowPlaying = "Now Playing: $info{name} - $info{artist}";
    }
}

#Set These
my $CPU='temp3';
my $MOBO='temp2';
my $FAN='fan2';


$UNAME = `uname -sr`;
chop($UNAME);
$MACHINE = `machine`;
$UPTIME = `uptime`;
chop ($UPTIME);
#--DISKSPACE--#
$HDD = `df -k | awk '{ sum+=\$2/1024^2 }; END { printf (\"%dGb\", sum )}'`;
#chop ($HDD);

#--DISKSPACE FREE--#
$HDDFREE = `df -k | awk '{ sum+=\$4/1024^2 }; END { printf (\"%dGb\", sum )}'`;
#chop ($HDDFREE);


$query = new CGI;
$query->import_names('webform');

my $username = "yourusername";
my $password = "yourpassworkd";
$DATA_2_SEND="CPU: $MACHINE | OS: $UNAME *<*Uptime: $UPTIME*<*Diskspace: $HDD Free: $HDDFREE*<*$nowPlaying";
#print $DATA_2_SEND;

my %form = ();

%form =('username' => $username,
   'password' => $password,
   'data'      => $DATA_2_SEND,
   'Submit'   => '');

my $ua = new LWP::UserAgent;
my $curl = url("http:"); 
my $req = new HTTP::Request 'POST','http://sigx.yuriy.net/update.php';
$req->content_type('application/x-www-form-urlencoded');
$req->content($curl->equery);
$curl->query_form(%form);
$req->content($curl->equery);
my $response= $ua->request($req)->as_string;


(Note: I make a few odd changes to the code I actually used on my system, like adding a hard coded CPU speed, and the 'Power Macintosh' bit after the Darwin version. And AFAIK you need Apple's Developer Tools (Xcode and the like) installed for any of this to work. But I'm probably only making sense to people who do have them installed)

_________________
Image


Top
 Profile  
 
 Post subject: urm... help?
PostPosted: Sat Apr 03, 2004 12:57 pm 
Offline

Joined: Sun Mar 28, 2004 10:22 pm
Posts: 2
Okay at cost of sounding like a horrible n00b...

I know nothing about perl... I'm running Mac OS X Panther and want to use sigX... will some kind person walk me through on how to set all this up? I just read through everything and I am so incredibly confused... :oops:


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 03, 2004 3:24 pm 
Offline

Joined: Sat Apr 03, 2004 3:07 pm
Posts: 1
Location: Manhattan
I've modified and made the code a little bit more robust. Allowing you to just configure things instead of having to comment out everything you don't want.

I added the xmms code as posted above by honkeykong. I added code to parse sensors output (for fan speed voltages temps etc). I also made it easy to display any info you want out of xmms-info and proc/cpuinfo by storing all the fields in a hash. Also supports displaying multiple cpus, though i only have 1. Fixed various other warnings etc. The code is a bit longer, but oh well.

DISCLAIMER: I'm not a perl genius. I've written enough scripts to know the basics. I'm sure there are probably better ways of doing than what i've done, but that's perl for you! Let me know if you run into any problems with it, it works on my system. I'm not responible for any damage to your computer due to this code. Always check code before running for the first time.


The output from it is in my sig below...


Code:
!/usr/bin/perl -w
# Credits     : This script was created by and is currently maintained
#               by Victor Igumnov [lamer0@lamer0.com].
#
# Legal Info  : Copyright (C) 2003, Victor Igumnov [lamer0@lamer0.com]
#
#               This program is free software. You may redistribute it
#               and/or modify it under the terms of the GNU General
#               Public License as published by the Free Software
#               Foundation; either version 2 of the License, or
#               (at your option) any later version.
#
#               This program is distributed in the hope that it will be
#               useful, but WITHOUT ANY WARRANTY; without even the
#               implied warranty of MERCHANTABILITY or FITNESS FOR A
#               PARTICULAR PURPOSE.  See the GNU General Public License
#               for more details.
#
#   This version had been modified by Chris Case <cc2382@columbia.edu>
$|=1;
use strict;
use CGI;
use URI::URL;
use LWP::UserAgent;
use Text::Wrap;

################ MODIFY THESE SETTINGS FOR YOUR SYSTEM ######################

# set username and password here
my $username = "foo";
my $password = "foo";

# set to 0 if you want to test the script w/o uploading. It will output to
# stdout instead
my $UPLOAD = "1";

# wrap text at 80 columns
$Text::Wrap::columns = 80;

# Set Distro Version
my $DISTRO = "Gentoo";

# Locations to various binaries for queries, use full paths for "better"
#security leave blank to not execute that query
my $UPTIMEBIN = "/usr/bin/uptime";
my $HOSTNAMEBIN = "/bin/hostname";
my $UNAMEBIN = "/bin/uname";
my $SENSORSBIN = "/usr/bin/sensors";
my @SENSORSTEMP = "temp2"; # array of temps for each cpu 0,1,2,3...etc
my @SENSORSFAN = "fan1";
my $FREEBIN = "/usr/bin/free";
#my $XDPYINFOBIN = "/usr/X11R6/bin/xdpyinfo";
my $XDPYINFOBIN;
#my $DFBIN = "/bin/df";
my $DFBIN;

# location to cpu info in proc
my $CPUINFOFILE = "/proc/cpuinfo";
my $XMMSINFOFILE="/tmp/xmms-info";

# other various binaries, you shouldn't need to change these unless yours are
# located somwhere else
my $GREP = "/bin/grep";
my $AWK  = "/bin/awk";
my $HEAD = "/bin/head";


#############################################################################
# Get uptime
my $UPTIME;
if ($UPTIMEBIN) {
  $UPTIME = `$UPTIMEBIN`;
  chomp ($UPTIME);
}

# Get hostname
my $HOSTNAME;
if ($HOSTNAMEBIN) {
  $HOSTNAME = `$HOSTNAMEBIN`;
  chomp ($HOSTNAME);
}

# Get OS and Version
my $UNAME;
if ($UNAMEBIN) {
  $UNAME = `$UNAMEBIN -sr`;
  chomp ($UNAME);
}


#Get cpu info
my @CPUINFO;    #cpuinfo is an array of hashes
if ( -r $CPUINFOFILE ) {
  open(CPUINFO_IN, $CPUINFOFILE) || warn("Warning: $!");
  my $proc_no = -1;

  #process all the lines
  while (<CPUINFO_IN>) {
    chomp;

    # index array by processor number
    if (/^processor\s*:\s*(\d+)$/) {
      $proc_no = $1;
    }
    # only parse lines with data!
    elsif (/\S+/){
      # split keys and values and clean them up then store into hash
      my @fields = split(/:/);
      my $key = shift(@fields);
      $key =~ s/^\s*(.+?)\s*$/$1/;
      my $value = join(":", @fields);
      $value =~ s/^\s*(.+?)\s*$/$1/;
      $CPUINFO[$proc_no]{$key}=$value;

      #print "CPU" . $proc_no . ": " . $key ."=" . $value . "\n";
    }
  }
  close CPUINFO_IN;
}

if ($SENSORSBIN) {
  for (my $i = 0; $i < scalar(@CPUINFO); $i++){
    $CPUINFO[$i]{'temp'} = `$SENSORSBIN| $GREP $SENSORSTEMP[$i]| $HEAD -n1|$AWK '{print \$2}'`;
    $CPUINFO[$i]{'fan'} = `$SENSORSBIN| $GREP $SENSORSFAN[$i]| $HEAD -n1| $AWK '{print \$2}'`;
    chomp $CPUINFO[$i]{'temp'};
    chomp $CPUINFO[$i]{'fan'};
  }
}

# Get Memory info
my %MEMINFO;
if ($FREEBIN) {
  #--PERCENTAGE OF MEMORY FREE--#
  $MEMINFO{'percent'} = `$FREEBIN|$GREP Mem|$AWK '{print (( \$3 -(\$6 + \$7) )/\$2)*100}'`;
  chomp ($MEMINFO{'percent'});
  $MEMINFO{'percent'} = sprintf('%.2f', $MEMINFO{'percent'});

  #--MEMORY FREE--#
  $MEMINFO{'free'} = `$FREEBIN|$GREP Mem |$AWK '{printf (\"%.0f\", ( \$3 -(\$6 + \$7) )/1000)}'`;
  chomp ($MEMINFO{'free'});

  #--TOTAL MEMORY--#
  $MEMINFO{'total'} = `$FREEBIN |$GREP Mem |$AWK '{printf (\"%d\", \$2/1000 )}'`;
  chomp ($MEMINFO{'total'});

  #--MEMORY USED?--#
  $MEMINFO{'used'}=$MEMINFO{'total'}-$MEMINFO{'free'};
}
#--SCREEN RESOLUTION--#
my $RES;
if ($XDPYINFOBIN) {
  $RES = `$XDPYINFOBIN| $GREP dimensions| $AWK '{print \$2}'`;
  chomp ($RES);
}


#--DISKSPACE--#
my %HDDINFO;
if ($DFBIN) {
  $HDDINFO{'total'} = `$DFBIN| $AWK '{ sum+=\$2/1024^2 }; END { printf (\"%d\", sum )}'`;
  chomp ($HDDINFO{'total'});

#--DISKSPACE FREE--#
  $HDDINFO{'free'} = `$DFBIN| $AWK '{ sum+=\$4/1024^2 }; END { printf (\"%d\", sum )}'`;
  chomp ($HDDINFO{'free'});
}

# let's get xmms info
my %XMMSINFO;    #xmmsinfo is a hash

# Make sure we can read the file
if ( -r $XMMSINFOFILE ) {
  open(XMMSINFO_IN, $XMMSINFOFILE) || warn("Warning: $!");

  #process all the lines
  while (<XMMSINFO_IN>) {
    chomp;

    # only parse lines with data!
    if (/\S+/){
      # split keys and values and clean them up then store into hash
      my @fields = split(/:/);
      my $key = shift(@fields);
      $key =~ s/^\s*(.+?)\s*$/$1/;
      my $value = join(":", @fields);
      $value =~ s/^\s*(.+?)\s*$/$1/;
      $XMMSINFO{$key}=$value;

    }
  }
  close XMMSINFO_IN;
}




my $DATA_2_SEND ="";

$DATA_2_SEND .= "Host: $HOSTNAME is " if ($HOSTNAMEBIN);
$DATA_2_SEND .= "$DISTRO $UNAME" if ($UNAMEBIN);
$DATA_2_SEND .= ", $RES resolution" if ($XDPYINFOBIN);
$DATA_2_SEND .= "\nUptime:$UPTIME" if $UPTIMEBIN;

for (my $i = 0; $i < scalar(@CPUINFO); $i++){
  $DATA_2_SEND .= "\nCPU$i: " . $CPUINFO[$i]{'model name'};
  $DATA_2_SEND .= " @ " .  $CPUINFO[$i]{'cpu MHz'} . "MHz";
  if ($CPUINFO[$i]{'temp'}){
    $DATA_2_SEND .=", temp: " . $CPUINFO[$i]{'temp'};
    $DATA_2_SEND .=" @ " .  $CPUINFO[$i]{'fan'} . "RPMs";
  }
}

if ($FREEBIN) {
  $DATA_2_SEND .= "\nMem: $MEMINFO{'total'}MB total";
  $DATA_2_SEND .= ", $MEMINFO{'used'}MB used";
  $DATA_2_SEND .= ", $MEMINFO{'free'}MB free";
}

if ($DFBIN) {
  $DATA_2_SEND .= ", Diskspace: $HDDINFO{'total'}GB total";
  $DATA_2_SEND .= ", $HDDINFO{'free'}GB free";
}

if (%XMMSINFO) {
  $DATA_2_SEND .= "\nNow " . $XMMSINFO{'Status'} . ": ";
  $DATA_2_SEND .= $XMMSINFO{'Title'};
}
else {
  $DATA_2_SEND .= "\nIt's quiet in here.";
}

# this wraps anything that may have gone too far across (like xmms info)
my @lines = wrap("","",$DATA_2_SEND);
$DATA_2_SEND = join('', @lines);
print $DATA_2_SEND . "\n" unless $UPLOAD;
$DATA_2_SEND =~ s/\n/\*\<\*/g;

if ($UPLOAD) {
  my $query = new CGI;
  $query->import_names('webform');
  my %form = ();
  %form =('username' => $username,
          'password' => $password,
    'data'         => $DATA_2_SEND,
          'Submit'   => '');

  my $ua = new LWP::UserAgent;
  my $curl = url("http:");
  my $req = new HTTP::Request 'POST','http://sigx.yuriy.net/update.php';
  $req->content_type('application/x-www-form-urlencoded');
  $req->content($curl->equery);
  $curl->query_form(%form);
  $req->content($curl->equery);
  my $response= $ua->request($req)->as_string;
}


-sol

_________________
Image


Top
 Profile  
 
 Post subject: Re: urm... help?
PostPosted: Sun Apr 04, 2004 7:43 am 
Offline

Joined: Thu Apr 01, 2004 2:13 pm
Posts: 5
MG wrote:
Okay at cost of sounding like a horrible n00b...

I know nothing about perl... I'm running Mac OS X Panther and want to use sigX... will some kind person walk me through on how to set all this up? I just read through everything and I am so incredibly confused... :oops:


Right, this is what I think I did:

1) Install Mac OS X Developer Tools. I did this ages ago, and installed all of it. I think you just need the command line tools and libraries, but it might be better if you installed everything, just in case (you need about a gigabyte of disk space IIRC.) It should either be on one of the Mac OS X installer CDs (if you bought Panther at retail), or as an archive somewhere in your Applications folder (if Panther came preinstalled.)

2) Install Mac::Glue. Open a terminal, and type this:

sudo perl -MCPAN -e 'install "Mac::Glue"'

Mac OS X will prompt you for your password, and then you'll have to configure Perl's automatic update stuff. IIRC theres an option to let it configure itself, use that. If it tells you it needs to install prerequisites, let it. (Pressing Enter at Perl's prompts will select the default option)

3) Install libwww-perl. I don't know the fancy automatic way of doing this, so I ended up downloading it and its prerequisites, and installing manually.
http://www.perl.com/CPAN/modules/by-module/Bundle/ has libwww-perl itself.
http://www.perl.com/CPAN/modules/by-module/URI/ has URI.
http://www.perl.com/CPAN/modules/by-module/HTML/ has html-parser and html-tagset.

Download the latest versions of those 4 modules (libww-perl, URI, html-parser and html-tagset) and uncompress them using Stuffit (which should just create separate folders for each of them).

Go to each module's directory in Terminal (if you don't know how to use Terminal / tcsh / a command line, your pretty stuffed I'm afraid), and run:

perl Makefile.pl
make
make test
sudo make install

You may be asked for your password again for the sudo bit. The order to install the modules is probably html-tagset, html-parser, URI then libwww-perl itself.

4) Create a glue for iTunes, so Perl can get what track your playing. Search for gluemac in Finder, it's icon is a Unix programme icon (black box). In my case it was in ~/.cpan/build/Mac-Glue-1.19/scripts/ , with a duplicate in a similar location. (~ is Unix shorthand for your home directory). If it's there, the command is:

sudo ~/.cpan/build/Mac-Glue-1.19/scripts/gluemac 'iTunes'

It'll ask for a glue name, just press [ENTER] to use the default of iTunes. I think you might need iTunes running, I'm not sure.

5) Assuming all the modules install correctly, use TextEdit / vi / editor of your choice to save my version of the Perl script (the others are based on Linux, and will only partly work, and bring up a dozen errors.) Remember to include all of the code I gave and to change the username and password to yours. Use Plain Text mode, not rich text, I think UTF-8 text encoding is what you need to use. I saved mine as sigx.pl in my home directory. Assume that type:

cd ~
chmod +x sigx.pl
./sigx.pl

And a Sigx should be created. Check if it worked on the website (it should appear in the preview area, and look similar to mine). If errors come up then somethings gone wrong somewhere, but it'd be hard to debug as I'm pretty clueless about Perl as well. I think cut and pasting the code might introduce loads of hidden characters to damage the code as well, which could cause problems as you'll need to do just that with my code. Unfortunately I don't have any webspace to upload a working / known good version of my script too either...

6) If the script is working, now all we need to do is add it to cron. Luckily a Mac GUI as available, at http://www.koch-schmidt.de/cronnix/. Add it, making sure NOT to prepend the /usr/bin/open command. Set everything but minutes to 'any', then go to the advanced tab, and but */2 for minutes. This should cause the script to run every two minutes when your logged in.

7) Modify the script to your personal tastes. The line:

$DATA_2_SEND="CPU: $MACHINE | OS: $UNAME *<*Uptime: $UPTIME*<*Diskspace: $HDD Free: $HDDFREE*<*$nowPlaying";

In the script controls the actual message. The *<* command is newline, and the $VARNAMEs are the bits that insert each dynamically generated part. To get rid of variables you don't want, just remove them. All the working variables are used in that version (mine fakes the CPU speed by adding it manually.) Make sure not to remove the " and the "; at the start and end, and don't use " in the actual text (I'm not sure about other special characters). I'm sure finding some Perl genius would be better.

Now if that hasn't scared you off, I don't know what will. Sorry about the badly writteness, I'm doing this in a rush, and I'm not much of a writer anyway...

(One thing I noted is that there's a specific iTunes Perl module as well, which might remove the need to mess around with Mac::Glue to get the iTunes bit working. But I don't have the time to do that sort of thing I'm afraid.)

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 10:06 pm 
Offline

Joined: Mon Mar 08, 2004 4:50 pm
Posts: 3
Anyone else find that their download/upload will reset after 4 gbs? I have had this happen about 4 times over the last month

_________________
Linux? Whats that.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 09, 2004 3:30 am 
Offline

Joined: Thu Apr 01, 2004 2:13 pm
Posts: 5
ocbeta wrote:
Anyone else find that their download/upload will reset after 4 gbs? I have had this happen about 4 times over the last month


That sounds like integer rollover, whatever keeps track of the downloads uses a 32bit Unsigned Integer, where 2^32 or around 4 billion is the maximum value storable. Once it gets to the maximum, it just goes back to 0. I think these scripts just get values that are generated by the OS, so its probably not a bug in the sigx script. Assuming that you're using Linux you should just fix the OS code yourself. :)

Either that or download less. :)

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 13, 2004 8:54 pm 
Offline

Joined: Tue Apr 13, 2004 8:52 pm
Posts: 1
Location: Miles City, MT, USA
Is there a *BSD version available? I'm running FreeBSD 5.2-CURRENT.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 13, 2004 11:05 pm 
Offline

Joined: Thu Apr 08, 2004 10:19 pm
Posts: 14
Location: Texas
If you look at the perl script the commands will be virutally the same. With the exception of /proc/cpuinfo and the free ram display. Commands like 'uptime' are universal to most any unix system.

Here's an example of the script unmodified on a netBSD box.

Image

_________________
Image
SigX makes internet radio better


Top
 Profile  
 
 Post subject: Proxy
PostPosted: Wed Apr 14, 2004 8:37 am 
Offline

Joined: Wed Apr 14, 2004 8:36 am
Posts: 2
caould one of yall write in a way to go through a proxy?


Top
 Profile  
 
 Post subject: Or umm
PostPosted: Wed Apr 14, 2004 12:10 pm 
Offline

Joined: Wed Apr 14, 2004 8:36 am
Posts: 2
nevermind, added proxy code, its all good now, YEE HAAAAA


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 68 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Fatal: Not able to open ./cache/data_global.php