Chern Jian Leaw wrote:
>
> Hi,
Hello,
> I have the script below which outputs some values in a "tabular" form into
> the body of a mail. I'm using the format utility in PERL to output the
> values in a tabular form as in:
>
> PROG NO VERSION PROTOCOL PORT SERVICE RESPONSE
> ----------------------------------------------------------------------------
> ----------------------------------------------------------------------------
> -----
> 10666567 1.1 tcp 5676 walld
> 10666567 program is not available.
>
> However, it produced the errors below:
> [EMAIL PROTECTED] file-5.pl names
> Format not terminated at file-5.pl line 97, at end of line
> Format not terminated at file-5.pl line 97, at end of line
> Missing right bracket at file-5.pl line 97, at end of line
> syntax error at file-5.pl line 97, at EOF
> Execution of file-5.pl aborted due to compilation errors.
>
> Below is my script which reads the file containing the output of the rpcinfo
> UNIX utility, as in:
> program vers proto port service response
> 100008 1 udp 55734 walld program 100008 version 1
> ready and waiting
> 1073741824 1 udp 661 program 1073741824 version 1
> is not available
> 1073741825 1 udp 899 program 1073741825 version 1
> is not available
>
> and mails to sys-admins whenever the program response is NOT "ready and
> waiting". The problem scenario is similar my earlier posting. However, I'm
> now wanting to include the formatting utility in PERL to better format my
> outputs.
>
> Below is my script which produced the ERROR output above:
>
> open(INPUT, "$file") || die "Can't open $file \n";
> open(NAMES, "$nameList") || die "Can't open $nameList \n";
> @names=<NAMES>;
> $list="";
> for($i=0;$i<@names;$i++){
> chomp($names[$i]);
> print "\$names[$i]=$names[$i] \n";
> $list=$list." "."$names[$i]".$domain;
> }
> my @data = grep{/^\d/ && !/(ready and waiting)$/ && !/^RPC/ && !/^program/}
> map {chomp; $_}$
> if(@data==0){
> print "No error rows found\n";
> exit 1;
> }
> else{
> print MAIL "SUBJECT: RPCPING OUTPUT \n";
> print MAIL "HOST :$hostName\n";
> print MAIL "IP :$ip\n";
> print MAIL "OS :$^O \n";
> foreach(@data){
> print "ELEMENTS: $_ \n";
> my @field=split(/:?\s+/,$_,6); ##break it up into 6 fields
>
> format STDOUT_TOP =
> MAIL
> PROG NO VERSION PROTO PORT SERVICE RESPONSE
>
> ----------------------------------------------------------------------------
> ----------------------------------
> .
> shift @field unless $field[0];
> $progNo = $field[0];
> $version = $field[1];
> $protocol = $field[2];
> $port = $field[3];
> $service = $field[4];
> $response =$field[5];
>
> write();
>
> format STDOUT =
> @<<<< @#.###### @<<<<<< @<<<<<< @#.###### @<<<<<<
> @<<<<<<<<<<<<<<<<<<<<
> $progNo, $version, $protocol, $port, $service, $response
> .
> }
> }
> close(MAIL);
>
> Could anyone help me out by showing me where did I go wrong and how do I
> resolve it? I'm still new in using the format utilty.
The dot terminator needs to be the first and only character on the line.
format STDOUT =
@<<<< @#.###### @<<<<<< @<<<<<< @#.###### @<<<<<<
@<<<<<<<<<<<<<<<<<<<<
^^^^^^^^^^^^ This whitespace will be included in the format.
$progNo, $version, $protocol, $port, $service, $response
.
^ WRONG!
format STDOUT =
@<<<< @#.###### @<<<<<< @<<<<<< @#.###### @<<<<<<
@<<<<<<<<<<<<<<<<<<<<
$progNo, $version, $protocol, $port, $service, $response
.
^ CORRECT
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]