Uptime on davesource.com



18:09:55 up 31 days, 23:42, 12 users, load average: 1.24, 1.26, 1.23





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);