LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-15-2009, 02:11 AM   #16
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,363

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751

Yeah; I was just being cautious and trying to allow for new 'headers'. It really does depend on the OP how picky he wants/needs to be.
 
Old 10-15-2009, 04:41 AM   #17
Lordandmaker
Member
 
Registered: Sep 2005
Location: London, UK
Distribution: Debian
Posts: 258

Original Poster
Rep: Reputation: 39
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 View Post
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!

Last edited by Lordandmaker; 10-15-2009 at 04:50 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
looping a dialog box in perl kdelover Programming 3 09-19-2009 03:42 PM
Beryl manager --- changing the window behaviour [minimizing] me4linux Linux - Software 3 03-16-2007 10:31 AM
weird behaviour with hashes in perl weird_guy Programming 0 06-22-2004 09:51 PM
Looping thru a list in a file BruceC Linux - Newbie 12 05-19-2004 08:51 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration