HI John & eveyone, I did solve the syntax error with regards to the format utility. However, when I tried including the format utility into the contents of the mail, the contents of the mail were empty.
Hence I tried writting the formatted contents into a text file and it worked. The only drawback is it did not include the headers: PROG NO VERSION PROTO PORT SERVICE RESPONSE --------------------------------------------------------------- when I defined the format to below into the text file: format FILE = FILE PROG NO VERSION PROTO PORT SERVICE RESPONSE --------------------------------------------------------------- . Could someone show me the method of getting the headers above to appear into the file? Currently, contents of the file are as shown: SUBJECT: RPCPING OUTPUT HOST :pglc0001 IP :127.0.0.1 OS :linux 1073741824 1 udp 661 program 1073741824 version 1 is not available 1073741825 1 udp 899 program 1073741825 version 1 is not available 1073741826 1 udp 756 program 1073741826 version 1 is not available 1073741827 1 udp 813 program 1073741827 version 1 is not available I would like to have it appear as: SUBJECT: RPCPING OUTPUT HOST :mickey IP :127.0.0.1 OS :linux PROG NO VERSION PROTO PORT SERVICE RESPONSE 1073741824 1 udp 661 program 1073741824 version 1 is not available 1073741825 1 udp 899 program 1073741825 version 1 is not available 1073741826 1 udp 756 program 1073741826 version 1 is not available 1073741827 1 udp 813 program 1073741827 version 1 is not available Could someone help me out with this problem? Attached is my new script which prints such format into a text file and mails it out. Thanks -----Original Message----- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Thursday, June 26, 2003 2:45 AM To: [EMAIL PROTECTED] Subject: Re: PERL format utility -error 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]
file-6.ZIP
Description: Zip compressed data
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]