On Sunday, December 15, 2002, at 06:06  PM, Riccardo Perotti wrote:

Puneet:

I just got my first "unix tip of the week"! (thanks to *your* tip)

I remember you said you used a script which placed each tip in some
browsable environment for future reference or something like that.

Would you care to share that script with me/us?

well, this is really very simple... geeks, please don't laugh. this is for newbies only.

1. I have a directory called unixtips.
2. I have the following files -- index.html, toc.pl, tipdetail.pl, unixtips.txt (files shown below)
3. index.html is a simple frame of two columns with a table of contents on the left (toc), and the main body for the tip on the right (tipdetail)
4. unixtips.txt contains the tips I copy from my email. Each tip starts with the words "TIP: " and ends with ====. Any code that one types is bounded by -- before and after.
5. that's it. ;-) I told you, it was simple. You can see the tips I have collected at
209.83.8.226/unixtips/index.html. The site is for personal use only, so don't be sending a dos attack against it ;-).

== index.html ==
<!-- frames -->
<frameset cols="40%,*">
<frame name="toc" src="toc.pl" marginwidth="10" marginheight="10" scrolling="auto" frameborder="0">
<frame name="tipdetail" src="tipdetail.pl" marginwidth="10" marginheight="10" scrolling="auto" frameborder="0">
</frameset>

== toc.pl ==
#!/usr/bin/perl -w
use strict;
use CGI::Pretty qw(:standard);
#use CGI::Carp qw(fatalsToBrowser);
$|++;

print header, start_html;
&toc;
print end_html;

sub toc {
open FH, "unixtips.txt" or die "can't open tips";
my $i = 1;
print "<ol>";
while (<FH>) {
if (s/^TIP: //) {
print "<li><a href='tipdetail.pl?tipnum=$i' target='tipdetail'>$_</a></li>";
$i++;
}
}
print "</ol>";
}

== tipdetail.pl ==
#!/usr/bin/perl -w
use strict;
use CGI::Pretty qw(:standard);
$|++;

my $tipnum = param("tipnum");

print header, start_html;
if ($tipnum ne "") {
&detail($tipnum);
} else {
print "Please choose a tip";
}
print end_html;

sub detail($tipnum) {
my $tipnum = shift;
my $i = 1;
my $tipflag;
my $codeflag = 0;
open FH, "unixtips.txt" or die "can't open tips";
print "<pre>";
while (<FH>) {
if (/^TIP:/) {
$tipflag = ($i == $tipnum) ? 1 : 0;
$i++;
}
if ($tipflag) {
if (s/^TIP: //) {
print "<h1>$_</h1>";
} elsif (/^--/) {
$codeflag = ($codeflag == 0) ? 1 : 0;
if ($codeflag) {
print "<font color='#ff0000'>";
} else {
print "</font>";
}
if ($codeflag) {
print "$_" if (!/^--/);
}
} else {
print;
}
}
}
print "</pre>";
}

== unixtips.txt ==
TIP: GETTING IPs FROM IFCONFIG

You can use ifconfig to lookup IP addresses bound to your box.
If you do not want to search the output from ifconfig, use the
following command to get just the IP listing.

--
ifconfig | awk '/inet/{print $2}' | awk -F: '{print $2}'
--

====

TIP: PATHS EASIER TO READ

Are your

--
% echo $PATH
--

and

--
% echo $LD_LIBRARY_PATH
--

unreadable? Try this to make for something that is much easier
to read:

--
echo $PATH | tr ":" "\n"
--

====

TIP: COMMENT OUT MULTIPLE LINES

Reply via email to