sub read_config_file { # Open and read configuration file specified as first passed parameter # $_[0]. Return the contents of the file as the hash array %config_param. # Lines beginning with "#" are treated as comments. It is assumed # that the indirect file contains lines as # Modified April 9, 2010. There is no @INC specification. rcg # Modified December 31, 2008. Add bco-dmo/perlmodule # location to @INC and require loading of # sendmessage.pl. rcg # Modified November 27, 2007. Add local definitions of # $error and $warning. rcg # Modified February 26, 2003. Remove leading and trailing spaces for # the key and value, but don't remove all spaces. # parameter := value # and this information is stored as # $config_param{"parameter"} = value my $filename = $_[0]; my ($parameter, $value, %config_param); my $error = "&x"; my $warning = "#"; #print STDOUT ("#**debug, indirect filename=$filename\n"); unless (defined $filename ) { &sendmessage ($error, "Could not open configuration file", "File name not specified. Cannot continue."); exit; } unless (open CONFIG_FILE, $filename) { &sendmessage ($error, "Could not open configuration file=$filename", "Error code=$!. Cannot continue."); exit; } while () { chomp; if (m/^#/) { next;} unless ( m/\S+/ ) {next;} unless ( m/:=/ ) { &sendmessage ($warning, "No :equal sign in line of config file=$filename", "Line is=$_"); next; } # print STDOUT ("***debug, config input line=$_\n"); ($parameter, $value) = split /:=/; $parameter =~ s/^\s+//; $parameter =~ s/\s+$//; $value =~ s/^\s+//; $value =~ s/\s+$//; $config_param{$parameter} = $value; # print STDOUT ("#**debug, config_param{$parameter}=", # $config_param{$parameter}, "\n"); } close CONFIG_FILE; return %config_param; } 1; sub sendmessage { # Send a message to the user, via e-mail and to STDOUT. # The message sent will be in the strings $_[1], $_[2], ... # The prefix string is contained in $_[0]. # November 27, 2007. Remove Nancy Copley from receiving # message as this is for BCO-DMO use. Rename sendmessage. # Add values for $error and $warning. rcg # April 30, 2007. Add -c option to mail and send carbon copy to # Nancy Copley. Fix spelling of problem. Handle # any number of output lines. From program sendmessage. # rcg # June 25, 2003. Change call to mail to be just mail so can export # routine to other systems without changes. # April 1, 2003. On Solaris, mail is located at /usr/bin/mail # not /bin/mail. RCG my ( @args, $i, $mailfile, $message0, $message1, $prefix, $who); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst); my $error = '&x'; my $warning = '#'; $prefix=$_[0]; unless (defined $prefix) { $prefix = "&x"; } ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); if ($year >= 100 and $year <= 1000) {$year = $year + 1900} if ($year < 1900) { $year = $year + 2000; } $mon++; if ($mon < 10) { $mon = "0" . $mon; } if ($mday < 10) {$mday = "0" . $mday; } if ($hour < 10) { $hour = "0" . $hour; } if ($min < 10) { $min = "0" . $min; } if ($sec < 10) { $sec = "0" . $sec; } undef $wday; undef $isdst; $mailfile="> /tmp/sendmess" . $year . $yday . $hour . $min . $sec . ".tmp"; if ( open TEMPFILE, $mailfile) { print TEMPFILE ("Message from $0\n"); if ( exists $ENV{'REMOTE_HOST'} ) {$who=$ENV{'REMOTE_HOST'} ; } elsif (exists $ENV{'REMOTE_ADDR'} ) {$who=$ENV{'REMOTE_ADDR'} ; } else {$who="not available"; } print TEMPFILE (" Date of message: $year/$mon/$mday $hour:$min\n"); print TEMPFILE (" From: $who\n"); for ($i=1; $i<=$#_; $i++) { print TEMPFILE ($_[$i], "\n"); } close TEMPFILE; `mail -s "Problem with $0" rgroman\@whoi.edu <$mailfile`; unlink $mailfile; } for ($i=1; $i<=$#_; $i++) { print STDOUT ($_[$i], "\n"); } print STDOUT ($prefix," Above message from $0\n"); print STDOUT ($prefix," Date of message: $year/$mon/$mday $hour:$min\n"); } 1;