Jump to content

My avatar script


Steve Scrimpshire
 Share

Recommended Posts

Going off of this concept I talk about here:

http://www.mandrakeusers.org/viewtopic.php...namic+signature

 

I adjusted it to be an avatar (this board's bbcode in sigs is messed up) to show my temps, too, because of my cool state-of-the-art MoBo that has sensors on it.

 

Here's the whole script

<?php

Header ("Content-type: image/png");

Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");

Header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");

Header("Pragma: no-cache");



$ut = strtok( exec("cat /proc/uptime"), "." );

$cputemp   =  exec("cat /proc/sys/dev/sensors/it87-isa-0290/temp1");

             $cputemps  = explode(" ",$cputemp);

             $roundcpu  = explode(".",$cputemps[2]);

$mobotemp  =  exec("cat /proc/sys/dev/sensors/it87-isa-0290/temp2");

             $mobotemps = explode(" ",$mobotemp);

             $roundmobo = explode(".",$mobotemps[2]);



$days  = sprintf( "%2d", ($ut/(3600*24)) );

        $days = trim($days);

$hours = sprintf( "%2d", ( ($ut % (3600*24))/3600) );

        $hours= trim($hours);

$min   = sprintf( "%2d", ($ut % (3600*24) % 3600)/60 );

        $min = trim($min);











$recorduptime= "uptimebest";

$fp2 = isset($fp2) ? $fp2 : fopen("$recorduptime",'r');

$fp2 = fopen("$recorduptime",'r');

      flock ($fp2,1);

      $best= fread ($fp2, filesize ($recorduptime));

      flock($fp2,3);

fclose($fp2);

$record = explode("|",$best);



if ($days > $record[0]){

   $fp2 = fopen("$recorduptime",'w');

          flock ($fp2,2);

          fwrite($fp2,"$days|$hours|$min");

          flock($fp2,3);

   fclose($fp2);

   }

if ($days == $record[0]){

   if ($hours > $record[1]){

       $fp2 = fopen("$recorduptime",'w');

              flock ($fp2,2);

              fwrite($fp2,"$days|$hours|$min");

              flock($fp2,3);

       fclose($fp2);

       }

   if ($hours == $record[1]){

       if ($min >= $record[2]){

           $fp2 = fopen("$recorduptime",'w');

                  flock ($fp2,2);

                  fwrite($fp2,"$days|$hours|$min");

                  flock($fp2,3);

           fclose($fp2);

           }

       }

    }



$fp2 = fopen("$recorduptime",'r');

      flock ($fp2,1);

      $best= fread ($fp2, filesize ($recorduptime));

      flock($fp2,3);

fclose($fp2);

$record = explode("|",$best);



$days = "$days"."d";

$hours = "$hours"."h";

$min = "$min"."m";



$dayz = "$record[0]"."d";

$hourz = "$record[1]"."h";

$minz = "$record[2]"."m";



$roundcpu[0] = $roundcpu[0] + 3;

$realcpu = "$roundcpu[0]"."°C";

$realmobo = "$roundmobo[0]"."°C";



$img = imagecreatefrompng("button.png");



      $bg = ImageColorAllocate($img, 211, 211, 211);

      $text_color = ImageColorAllocate ($img, 255, 255, 255);

      $title_color = ImageColorAllocate ($img, 205, 205, 205);



      ImageString($img, 3, 57, 25, "Uptime", $title_color);

      ImageString($img, 3, 48, 38, "$days $hours $min", $text_color);

      ImageString($img, 3, 36, 58, "Record Uptime", $title_color);

      ImageString($img, 3, 48, 71, "$dayz $hourz $minz", $text_color);

      ImageString($img, 3, 20, 108, "CPU", $title_color);

      ImageString($img, 3, 17, 121, "$realcpu", $text_color);

      ImageString($img, 3, 115, 108, "MoBo", $title_color);

      ImageString($img, 3, 115, 121, "$realmobo", $text_color);



      ImagePNG($img);

      

ImageDestroy($img);

?>

Of course this line:

$img = imagecreatefrompng("button.png");

pulls from the background image I mad with Gimp named button.png and plced it in the same directory.

 

I got the info for the sensors from installing the lm_sensors package and running sensors-detect. Your path to the two temps are going to be named differently depending on the MoBo sensor. Of course, the adjustment I make to the CPU temp (+3) is only because Linux reports the temp 3 degrees lower than the BIOS does.

Link to comment
Share on other sites

Uh, thanks. I wasn't fishing for compliments. ;) I posted this because someone PM'ed me asking about it and I thought it would be useful for others to know, too. Plus, I thought that when I tried to send him a PM with the code in it that it didn't go because I didn't see it in my sent box until like ten minutes after I sent it. :D

Link to comment
Share on other sites

just an other update to my problem. I understood from one of Steve Scrimpshire's pm that I had to install lm_sensors to get the sensors active. While I was installing it via MCC >> install packages... it picked up a couple of other dependencies,

ksensors-0.7.2-4mdk.i586.rpm and

liblm-sensors1-2.7.0-2mdk.rpm

 

I installed all 3 and then did a re-boot(not knowing if i had to) and then when I logged-in I found a programme called ksensor start automatically. I realised it was the rpm package I just installed. I then configure it and I see some graphical displays of my system... swp, cpu state, up time, ram, etc

 

So that means the sensor is working. ... but my problem is still with the /proc sensor files containing nuthing in there. Could anyone be able to shed some light on this ?

Link to comment
Share on other sites

You might want to post a new topic about this.

 

BOT: My avatar that this topic refers to is temporarily offline until I move. I had to move the cable modem over to the Win2K computer here which will not forward ports properly. My avatar should return next week when I get back to Mississippi and get all settled in.

 

Edit: As you can now see...my avatar is back. :-)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...