Uptime on davesource.com



01:30:25 up 14 days, 10:18, 0 users, load average: 1.07, 1.10, 1.13





This script self prints (is a "Quine") [uptime.cgi]:


#!/usr/bin/perl

($PROGNAME = $0) =~ s|.*/||;

#########################
# Header
#########################
my $host = `hostname`;
print <<END_OF_HEADER;
Content-type: text/html

<body bgcolor=white>

<br><br><br><br>

<h1>Uptime on $host</h1>

<br><br>
<h3>
END_OF_HEADER

#########################
# Uptime
#########################
$|=1;
system("/usr/bin/uptime");

#########################
# Footer
#########################
print <<END_OF_FOOTER;
</h3>
<br><br><br>

<p><hr><p>

<pre>
This script self prints (is a "Quine") [$PROGNAME]:

END_OF_FOOTER

#########################
# Self-printing
#########################
print "<font size=-1>\n";
open(ME,$0) || exit;
while(<ME>) {
  # Goofy tricks to make it print out properly.
  s/&lt;/{"&DONT"."BREAKlt;";}/eg;
  s/&gt;/{"&DONT"."BREAKgt;";}/eg;
  s/</&lt;/g;
  s/>/&gt;/g;
  s/DON[T]BREAK/<nobr>/g;
  print;
}
close(ME);