Chern Jian Leaw wrote: > HI, > I have a script attached in this mail which reads the output of rpcinfo and > tokenizes its outputs. This problem is similar to my earlier posting a few > days ago. However, in this scenario, the some outputs of rpcinfo response > i.e. "rpcinfo: RPC: Timed out program 1073741825 version 1 is not > available" overflowed to the next line. Those rpcinfo response outputs which > did not overflow to the next lines are shown below e.g "program 100002 > version 2 ready and waiting". > > # cat weird > RPC PING pgadm1 > program vers proto port service response > 100002 2 udp 55733 rusersd program 100002 version 2 ready and > waiting > 100008 1 udp 55734 walld program 100008 version 1 ready and > waiting > 1073741825 1 udp 64018 rpcinfo: RPC: Timed out > program 1073741825 version 1 is not available > 100003 2 udp 55733 sprayd program 100003 version 2 ready and > waiting > > I would like to ignore those "overflowing" outputs whenever the response > does not have the status "ready and waiting". i.e. I would just like to > obtain the line: > rpcinfo:RPC:Timed out, and ignore the next line "program 1073741825 version > 1 is not available". > > Hence, I tried inserting a check in the script as below. It tries ignoring > the next line which does not begin with a digit. All rpcinfo outputs > produces the program number at the beginning i.e. digits. > > while(<INPUT>){ > print "Here ...\n"; > next if(/^RPC/); > next if(/^program/); > next if(/(ready and waiting)$/); > > $_=~m/^(\d+)\s+(\d+)\s+(\w+)\s+(\d+)\s+(\w+)[\s\:]+(.*)$/; > next if(/^\w+/); [CHECK INSERTED HERE] > print "prog no = $1\n"; > print "version = $2\n"; > ................... > > } > However, the output produced is shown below: > % ./file-3a.pl > /home/weird opened successfully > Here ... > Here ... > Here ... > Here ... > prog no = > version = > protocol= > port = > service = > response = > > The expected output, assuming everything is correct, would have a mail > generated with the format below: > Date: Tue, 10 Jun 2003 18:48:28 +0800 (MAL) > From: ASEC - Leaw Chern Jian <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED] > Subject: RPCPING OUTPUT > > PROG NO VER PROTO PORT RESPONSE > > 1073741825 1 udp 64018 > rpcinfo: RPC: Timed out > > Could anyone show me where did I go wrong and the method to resolve this > problem? > > ALSO, I would like to know the way which I could write the script to check > if there're completely no rows in the file which contains "ready and > waiting" , hence no mail should be generated. Could someone also show me how > could such checks be incorporated into my current script?
You seem to have taken no notice of the help we gave on the previous post. Put use strict; use warnings; at the head of your script, and declare your variables properly, and either use 'split' as I suggested or explain why you don't want to. You're not consistent about whether you want to include "ready and waiting" lines or not. Your code ignores all such lines, but you say you don't want to send mail if there are no lines which contain this string. I've assumed you want to ignore them. The program below will work. Rob my @data = grep { /^\d/ && !/ready and waiting/ } map { chomp; $_} <DATA>; if ( @data == 0 ) { print "No rows found\n"; } else { foreach (@data) { my @field = split /:?\s+/, $_, 6; $" = '] ['; print "[EMAIL PROTECTED]" } } __DATA__ RPC PING pgadm1 program vers proto port service response 100002 2 udp 55733 rusersd program 100002 version 2 ready and waiting 100008 1 udp 55734 walld program 100008 version 1 ready and waiting 1073741825 1 udp 64018 rpcinfo: RPC: Timed out program 1073741825 version 1 is not available 100003 2 udp 55733 sprayd program 100003 version 2 ready and waiting OUTPUT [1073741825] [1] [udp] [64018] [rpcinfo] [RPC: Timed out] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]