First, some background:
I work for a company with six sites, and until last week the four of us in IT were split into two, covering three sites each. As of Monday, we're a group of three covering all six, and a single person working completely on another long-term project. Since I'm crap at remembering things, I wanted an easy way to document the info about my 'new' sites, and a reasonable place to point the two who're now looking after 'my' sites.
I'd settled on plain text 'cause all our Windows servers have Putty on them, and so I can just ssh to my workstation to check the info. But, with the other people wanting the same information, I figured that rather than replicate it, I'd just write a script to read my plain text into a nice web page for them.
Quote:
Originally Posted by Telemachos
I had written a script, but then I realized that there's some key information I don't yet have. So, some questions:
[list][*]How closely does your sample model the real data? For example, do all the entries under Servers: really begin with scan-something and do the Services: and Servers: entries always start with a capital letter?
|
Ish. The format of the data file is of my design, too. The headings start with capital letters and end with a colon, and no other lines do. Lists are all tab-delimited.
Different sites have different prefixes for their servers (we have scan- service- jup- hayes- and sals- and a couple of others that were never quite brought into line).
But I also want to add other info (in fact, I already have - people, as a rough record of who can sign what off).
Quote:
Also, is your ftp line right? It has no associated server.
|
Sort-of. They're filled in off a template which has all the left-column in already, and covers all the services that most sites have.
Quote:
[*]Do the files switch only once (a block of Server: entries, followed by a block of Services: entries) or do they go back and forth.
|
Only once
The script as it stands is as below.
I've added a People header, and a Nuances header. Nuances are just lists of oddities about that site, and people is a list of the top bits of the company, and handy contacts (Managing Director, Financial Director, Production Director and nominated geek).
I've abandoned the more complex (and informative) layout I was initially aiming for in favour of doing some work that actually needs doing and just making the thing work (and, obviously, browsing forums), which is why it's incredibly repetitive at the minute. But it does everything it needs to do, I've just got to work out exactly what else I want(ed) it to do, an implement that.
Code:
#! /usr/bin/perl
use strict;
use CGI qw(param);
#use warnings;
print "content-type: text/html\n\n";
print "<html>\n\n";
print "<a href=\"..\">up</a><br />";
my @files =<*>;
@files = sort(@files);
foreach my $file (@files){
if ($file !~ /\.pl$/ && $file !~ /^\./ && $file !~ /template/ && $file !~ /^ip$/){ #If file is neither perl nor hidden
print " <a href=\"?site=".$file."\">$file</a> |";
}
}
print "<hr/>";
my $file = param('site');
open (FILE, "<$file") || die ("Error opening $file");
my (%services,%servers,%people,$nuances,$header);
while (<FILE>){
my $line = $_;
chomp $line;
if ($line =~ /:$/){
$header = $line;
}else{
if ($header =~ /Servers/){
my($key,$value)=(split(/\t/, $line))[0,1];
$servers{$key}=$value;
}elsif($header =~ /Services/){
my($key,$value)=(split(/\t/, $line))[0,1];
if ($value !~ /^$/){$services{$key}=$value;}
}elsif($header =~ /People/){
my($key,$value)=(split(/\t/, $line))[0,1];
$people{$key}=$value;
}elsif($header =~ /Nuances/){
$nuances .= "\n".$line;
}
}
}
close FILE;
print "<h2>$file</h2>\n";
print "<h4>Services</h4>\n<table border=\"1\">\n";
foreach my $key (sort(keys(%services))){
print "<tr><td>".$key."</td><td>".$services{$key}."</td></tr>\n";
}
print "</table>\n";
print "<h4>Servers</h4>\n<table border=\"1\">\n";
foreach my $key (sort(keys(%servers))){
print "<tr><td>".$key."</td><td>".$servers{$key}."</td></tr>\n";
}
print "</table>\n";
print "<h4>People</h4>\n<table border=\"1\">\n";
foreach my $key (sort(keys(%people))){
if ($people{$key} =~ /,/){
my @people=split(/,/, $people{$key});
print "<tr><td>$key</td><td>";
foreach (@people){
print "<a href=\"mailto:$_\">$_</a> ";
}
print "</td></tr>\n";
}else{
print "<tr><td>$key</td><td><a href=\"mailto:$people{$key}\">$people{$key}</a></td></tr>";
}
}
print "</table>\n";
print "<h4>Nuances</h4>";
print "<pre>\n";
print $nuances;
And thank you for such a detailled response! This forum never ceases to amaze me on just how willing to help the members are. Thank you!