Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Using F$Parse to grab a version number

SOLVED
Go to solution
Rick Dyson
Valued Contributor

Using F$Parse to grab a version number

I thought I understood that F$Parse would return the actual version number of a file. I want to monitor some log files that keep hitting 32767 versions too fast. :(

An test I just did:

$ dir net$server.log

Directory DISK$ICS:[DYSON]

NET$SERVER.LOG;657 NET$SERVER.LOG;656

Total of 2 files.
$ x = f$parse ("NET$SERVER.LOG",,,"VERSION")
$ sho sym x
X = ";"

What am I missing or doing wrong? I wanted to see the string "657". The on-line help suggests to me it should:

field

Specifies a character string containing the name of a field
in a file specification. Specifying the field argument causes
the F$PARSE function to return a specific portion of a file
specification.

Specify one of the following field names (do not abbreviate):

NODE Node name
DEVICE Device name
DIRECTORY Directory name
NAME File name
TYPE File type
VERSION File version number


Thanks,
Rick
11 REPLIES
Karl Rohwedder
Honored Contributor
Solution

Re: Using F$Parse to grab a version number

Rick,

try a

$ tmp = F$Search("NET$SERVER.LOG;*")
$ if (tmp.nes."")
$ then
$ vers = F$Parse("''Tmp'",,,"version")-";"
$ if (vers.gt.....)
$ endif

regards Kalle
Rick Dyson
Valued Contributor

Re: Using F$Parse to grab a version number

Thank you for the idea Karl.

That will provide me with what I am looking for! I guess I just am reading the on-line help wrong for the F$Parse. It see it parses the literal string that is provided and if no version number is provided, it comes up empty. I read it that it takes the filespec and provides you with the version number (and I assumed unless otherwise specified, the current highest number). Apparently not. :)

Thanks!

Rick Dyson
Valued Contributor

Re: Using F$Parse to grab a version number

I think I just read the on-line help incorrectly. Using a F$search for any/all files in a loop with the F$parse is apparently the approach that was probably intended.

Rick
Hoff
Honored Contributor

Re: Using F$Parse to grab a version number

You defaulted the version in your original code, and f$parse indicates that with the ; result. DCL is working as intended, in other words.

What problem might you be seeking to address here?

If it's renumbering the versions of the NETSERVER log files lower and/or dealing with the impending ;32767 version, there's an easier way, assuming you can quiesce the environment briefly: http://64.223.189.234/node/456
Rick Dyson
Valued Contributor

Re: Using F$Parse to grab a version number

Hi Hoff,

it is not netserver, per say. It is actually a problem with Process Software's SSH server. We are seeing as many as 10's of thousands of SSH connections per day tyring brute force password hacks. Each attempt opens a SSHD.LOG file. When the version gets to 32767, it starts doing crazy things, sometimes denying access, other times putting log session contents into data streams that are occurring in the session that does connect, etc.

Netserver (net$server) has caught me in the past, but never over and over again on time scales of a few days. More like once every few years. :)

I wanted a quick way to monitor the current version number and notify me of it approaching some threshold.

I did not fully grasp the description. I think I got it now once I saw an example of how Karl suggested using it.
Hoff
Honored Contributor

Re: Using F$Parse to grab a version number

If you have the option, consider moving ssh off of port 22, and to another port. This greatly reduces the effects of the brute-force attacks.

I'd definitely ring up Process and see if they can rework sshd some to avoid this situation.
Steven Schweda
Honored Contributor

Re: Using F$Parse to grab a version number

John Gillings
Honored Contributor

Re: Using F$Parse to grab a version number

As of V8.2 you can use DIRECTORY to find files nearing version limits:

$ DIRECTORY /SELECT=VERSION=MINIMUM=30000 disk:[000000...]*.*;

Once found, assuming a reasonably quiescent system, you can reset the version numbers with:

$ RENAME file.typ;* file.typ_TMP;
$ RENAME file.typ_TMP; file.typ;

This will take all existing versions of a file and renumber them in the same sequence starting from 1. The trailing semicolon is required.

Here's a procedure either reset a single file, or search for, and reset them:

VERSION_RESET.COM
$ IF F$EXTRACT(0,1,p1).EQS."#"
$ THEN
$ target=p1-"#"
$ GOTO 'target'
$ ENDIF
$
$ files=F$PARSE(";",p1,"SYS$DISK:[000000...]*.*;")
$ lim=p2
$ IF lim.EQS."" THEN lim="30000"
$ PIPE DIRECTORY/NOHEAD/NOTRAIL/SELECT=VERSION=MINIMUM='lim' 'files' | -
@'F$PARSE(";",F$ENVIRONMENT("PROCEDURE"))' #PROCESS SYS$PIPE
$ EXIT
$
$ PROCESS:
$ IF p2.EQS."" THEN p2="SYS$PIPE"
$ OPEN/READ in 'p2'
$ loop: READ/END=EndLoop in line
$ @'F$PARSE(";",F$ENVIRONMENT("PROCEDURE"))' #RESET 'line'
$ GOTO loop
$ EndLoop: CLOSE in
$ EXIT
$
$ RESET:
$ typ=".$"
$ IF F$PARSE(p2,,,"TYPE").EQS.typ THEN typ=".Z"
$ RENAME 'F$PARSE(";*",p2)' 'F$PARSE(";",typ,p2)'
$ RENAME 'F$PARSE(";*",typ,p2)' 'F$PARSE(";",p2)'
$ EXIT

usage:

to search for and reset multiple files

$ @VERSION_RESET filespec [minimum-version]

or for a single file

$ @VERSION_RESET #RESET filespec

A crucible of informative mistakes
The Brit
Honored Contributor

Re: Using F$Parse to grab a version number

Rick,
If you want a 'one-liner', try

$ X = $f$elem(1,";",f$search("NET$SERVER.LOG",))

Dave
Hoff
Honored Contributor

Re: Using F$Parse to grab a version number

re:

f$elem(1,";",f$search("NET$SERVER.LOG",))

I'd suggest:

f$parse(f$search("LOGIN.COM"),,,"VERSION")

Shopping for characters in filenames -- embedding syntax -- caused problems for applications moving to ODS-5.

Dave's suggested DCL will tip over with more than semicolon in a filename, something which is quite legal in an ODS-5 filename. (You do have to escape it, but the f$element technique doesn't catch the escapement.)

The engineer that coded up PCSI made that same basic local-parsing mistake, and the PCSI filename-parsing code mis-parses a number of valid file names when last I checked. There was a bug report, FWIW.

"Filename Parsing: Don't Try This At Home"
http://10.1.2.7/node/71
Steven Schweda
Honored Contributor

Re: Using F$Parse to grab a version number

> "Filename Parsing: Don't Try This At Home"
> http://10.1.2.7/node/71

10.1.2.7? Don't try it anywhere else.