Operating System - OpenVMS
1751890 Members
5115 Online
108783 Solutions
New Discussion юеВ

Re: Diplaying TOP 10 messages of a file

 
SOLVED
Go to solution
Jan van den Ende
Honored Contributor

Re: Diplaying TOP 10 messages of a file

Sk,

on your VMS version, you are practically restricted to:

$ TYPE /TAIL=<#-of-lines> /OUT=SYS$LOGIN:TAILTYPE.TMP
$ MAIL SYS$LOGIN:TAILTYPE.TMP
$ DELETE SYS$LOGIN:TAILTYPE.TMP;*

hth

Proost.

Have one on me.

jpe

Don't rust yours pelled jacker to fine doll missed aches.
Heinz W Genhart
Honored Contributor
Solution

Re: Diplaying TOP 10 messages of a file

Hi

I wrote 2 versions of a small hack. First example selects the first ten lines of a given file and sends it to a mail address. In both examples You must substitute the mail adress (xy) with Your own address.

$! Copies first 10 Lines of a file into a temporary file and sends this file to mail_address
$!
$ ON CONTROL_Y THEN GOTO clean_up
$ unique_filename = F$UNIQUE()
$ mail_address = "xy"
$ max_lines = 10
$ IF P1 .EQS. "" THEN INQUIRE P1 "Enter File Name "
$ IF F$SEARCH(P1) .EQS. ""
$ THEN
$ WRITE SYS$OUTPUT "File ''P1' not found "
$ GOTO clean_up
$ ENDIF
$ OPEN/READ in 'P1'
$ OPEN/WRITE out 'unique_filename'.dat
$r_loop:
$ READ/END_OF_FILE=end_file in record
$ WRITE out record
$ max_lines = max_lines -1
$ IF max_lines .GT. 0 THEN GOTO r_loop
$!
$end_file:
$ CLOSE in
$ CLOSE out
$ MAIL/SUBJECT=test 'unique_filename'.dat 'mail_address'
$clean_up:
$ IF F$TRNLNM("in") .NES. "" THEN CLOSE in
$ IF F$TRNLNM("out") .NES. "" THEN CLOSE out
$ DELETE 'unique_filename'.dat;*
$ EXIT


Second example writes the 10 last lines of a file into a temporary file and sends it by email

$! Creates a temporary file which contains the last ten lines of a given file. Se
$! sends the temporary file by mail
$!
$ ON CONTROL_Y THEN GOTO clean_up
$ mail_address = "xy"
$ IF P1 .EQS. "" THEN INQUIRE P1 "Enter Filename "
$ IF F$SEARCH(P1) .EQS. ""
$ THEN
$ WRITE SYS$OUTPUT "File ''P1' not found "
$ GOTO clean_up
$ ENDIF
$ unique_filename = F$UNIQUE()
$ TYP/TAIL=10 'P1'/OUT='unique_filename'.dat
$ MAIL/SUBJECT=test 'unique_filename'.dat 'mail_address'
$clean_up:
$ IF F$SEARCH("''unique_filename'.dat") .NES. "" THEN DELETE 'unique_filename'.dat;*

Hope that helps.

Heinz
Jan van den Ende
Honored Contributor

Re: Diplaying TOP 10 messages of a file

Heinz,

look at his previous post: he is at VMS 7.1, so no F$UNIQUE available!

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Jan van den Ende
Honored Contributor

Re: Diplaying TOP 10 messages of a file

Sk,

from your Forum Profile:


I have assigned points to 63 of 140 responses to my questions.

Some of those are rather old.

Maybe you can find some time to do some assigning?

http://forums1.itrc.hp.com/service/forums/helptips.do?#33

Mind, I do NOT say you necessarily need to give lots of points. It is fully up to _YOU_ to decide how many. If you consider an answer is not deserving any points, you can also assign 0 ( = zero ) points, and then that answer will no longer be counted as unassigned.
Consider, that every poster took at least the trouble of posting for you!

To easily find your streams with unassigned points, click your own name somewhere.
This will bring up your profile.
Near the bottom of that page, under the caption ├в My Question(s)├в you will find ├в questions or topics with unassigned points ├в Clicking that will give all, and only, your questions that still have unassigned postings.

Thanks on behalf of your Forum colleagues.

PS. ├в nothing personal in this. I try to post it to everyone with this kind of assignment ratio in this forum. If you have received a posting like this before ├в please do not take offence ├в none is intended!

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Heinz W Genhart
Honored Contributor

Re: Diplaying TOP 10 messages of a file

Sorry, I did not see what VMS Version he uses.

On vms 7.1 just change the line

unique_filename = F$UNIQUE()

to

unique_filename ="temp_file_''F$GETJPI("","PID")'"

That will solve the problem with the missing F$UNIQUE Lexical
Hein van den Heuvel
Honored Contributor

Re: Diplaying TOP 10 messages of a file


If your system supports the PIPE command you don't need an intermediate file:

$pipe type/tail=10 more_test.tmp | mail/subj="testing" sys$pipe hein


Unfortunately this TYPE/TAIL fails on STM_LF files with:
-SYSTEM-E-UNSUPPORTED, unsupported operation or function
-RMS-F-ORG, invalid file organization value

That's really silly because it is trivial to implement, but there you have it.
The workaround is to use an intermediate file, but then we're back to having to name that. (And no, $type/page does not work on a pipe :-( ).

In the thinking outside the box solutions, I thought the following might work:

$ i = 0
$open/read x test.tmp
$open/read y test.tmp
$loop1:
$read x x
$i = i + 1
$if i.lt.10 then goto loop1
$
$loop2:
$read/end=send_mail x x
$read y y
$goto loop2
$
$send_mail:
$mail/subj="last 10" y hein
$!type y
$close x
$close y


Well... it works for $type, but not for $mail ?!

Hein.