aru Posted January 14, 2003 Report Share Posted January 14, 2003 tobyink Frequent user Joined: 08 May 2002 Posts: 185 Location: London, England Post Posted: Mon Jul 22, 2002 6:13 pm Post subject: Add your system uptime to your MUB signature! _________________________________________________________________ First step is to put your system uptime into an image file. Due to patent issues, we'll be using PNG. Here is a Perl script to do this. It requires Perl and ImageMagick: Code: #!/usr/bin/perl ############################################################################## # uptime2png - Displays your kernel and uptime as a PNG file. # # Copyright (C) 2002 Toby A Inkster # # # # This program is free software; you can 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. # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the Free Software # # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################## $numberOfArgs = $#ARGV + 1; if ($numberOfArgs < 2) { print STDERR <<EOF; uptime2png - Displays your kernel and uptime as a PNG file. Usage uptime2png [background image] [output image] [colour] ----------------------------------------------------------- Copyright (C) 2002 Toby A Inkster <tobyink@goddamn.co.uk> License: GPL (see source for details) ----------------------------------------------------------- Background image should be roughly 200x50 pixels. It is a required parameter. The output image is also required. To read from/print to STDIN/STDOUT, use "-" as the file name. Both images should be in PNG format. The colour paramenter specifies the colour for the text. It is optional. EOF } else { # Here be monsters... ($s,$d)=split(/load/,`uptime`);($d,$s)=split(/up/, $s);chop($s);chop($s);chop($s);$s=~s/^s//;$s=~ s/s+/ /g;($a,$b,$c)=split(/, /,$s);$s="$a, $b"; if($s=~m/user/){($s,$a)=split(/,/,$s);}$r=`uname -rs`; chomp($r); $UPTIME = $s; $OPERATINGSYSTEM = $r; $INIMG = shift @ARGV; $OUTIMG = shift @ARGV; $COLOUR = shift @ARGV; $COLOUR = 'black' if ($COLOUR eq ''); $cmd = "convert -fill $COLOUR -draw " . "'text 20,20 "$OPERATINGSYSTEM" text 20,38 "Uptime: $UPTIME"' " . "png:$INIMG png:$OUTIMG"; system($cmd); } Put this in a cron job to create a new PNG every few minutes. Also as part of your cron job, upload it to your webspace. ncftpput will be your friend. Then, in your MUB signature, embed that image. DOlson Moderator Joined: 16 Apr 2002 Posts: 2393 Location: Canada Post Posted: Mon Jul 22, 2002 7:30 pm Post subject: _________________________________________________________________ I was wondering how to do that, really. But anyhow, I wouldn't be doing that on this system, as I shut it down at night now. Why? Because it's too bloody hot here! But my server... Hmm... Maybe I will do it for my server. delboy711 Senior user Joined: 03 May 2002 Posts: 412 Location: Wokingham, UK Post Posted: Mon Jul 22, 2002 9:44 pm Post subject: Nice _________________________________________________________________ Very nice. I had to make two changes to get it to run on my system. Quote: Both images should be in PNG format. The colour paramenter specifies the colour for the text. It is optional. EOF } else { I had to put a new line before the EOF or else it would not compile when no arguments are given. (I do not know why) Quote: $cmd = "convert -fill $COLOUR -draw " convert could not find the default font, so I had to change this to $cmd = "convert -font /usr/share/fonts/default/Type1/n019043l.pfb -fill $COLOUR -draw " theYinYeti Senior user Joined: 13 May 2002 Posts: 452 Location: Cannes (France) Post Posted: Tue Jul 23, 2002 8:56 am Post subject: _________________________________________________________________ My system up-time is always less than 12 hours, because I shut it down on night. It's better for the planet. Editor's note: This thread was originally posted at the old MUB (Mandrake User Board at club-nihil). This post is the result of a 99% automatic backup, so due to its nature some text may be lost (improbable but possible). Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted January 14, 2003 Report Share Posted January 14, 2003 I had one posted on the old, old board. It shows your uptime dynamically as well as your record uptime. Something like this: This all assumes that you have Apache, PHP (with the gd module) installed and, of course, mod_php for PHP to work with Apache. This board allows images in your signature in this format: [ img ]http://yourbox.com/yourimage.png[ /img ] without the spaces, of course. I set up an account with no-ip.com (free) for Dynamic DNS (I don't use this dynamic signature anymore, only because I moved and am no longer on DSL, but now on dialup) So, you create a directory in the /html portion of the site your Apache serves up on your box to hold this image (in my case, it's called /phpimage) You create a little PHP script that creates the image (it requires gd to work and that's on your disks...not sure about the downloaded ones, but I think it's there, too) and save it as whatever.png. Then you create an .htaccess file in that directory with this in it: AddType application/x-httpd-php .png If you want your image to be a .gif, just change that there. Then your image whatever.jpg would actually be a PHP script. This is what mine looks like: <?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" ), "." ); $days = sprintf( "%2d", ($ut/(3600*24)) ); $hours = sprintf( "%2d", ( ($ut % (3600*24)) / 3600) ); $min = sprintf( "%2d", ($ut % (3600*24) % 3600)/60 ); $days = trim($days); $hours= trim($hours); $min = trim($min); $img = @ImageCreate(245,60); $recorduptime= "uptimebest"; $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); $bg = ImageColorAllocate($img, 211, 211, 211); $text_color = ImageColorAllocate ($img, 0, 0, 0); $title_color = ImageColorAllocate ($img, 0, 0, 205); ImageString($img, 3, 3, 1, "Last Reboot of My Linux Box: ", $title_color); ImageString($img, 3, 3, 15, "$days days, $hours hours, $min minutes ago", $text_color); ImageString($img, 3, 3, 29, "Record Uptime:", $title_color); ImageString($img, 3, 3, 43, "$record[0] days, $record[1] hours, $record[2] minutes", $text_color); ImagePNG($img); ImageDestroy($img); ?> If you want it to be a .gif, you change it in here, too. Only very recent versions of gd allow .gif and you can make the bg of your image transparent if you use this option. I haven't tried to do that yet, I don't remember how to make it transparent, and the site I learned this little trick on is gone (or the posts about it have been deleted, actually, the site's still there...lol). Actually, it went exactly like that. Bits of code I borrowed from several places. _________________ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.