Operating System - OpenVMS
1753847 Members
8651 Online
108807 Solutions
New Discussion юеВ

Re: Directory Change Notification - ODS-2/ODS-5

 
SOLVED
Go to solution

Re: Directory Change Notification - ODS-2/ODS-5

Rob: Thanks! It would probably need some sort of blessing from my app vendor. But yes, this is exactly what I was after... too bad some tool doesn't come with the standard VMS distribution that can do this...

Jan: Very good point! I'd totally forgotten this on the VMS end... the processing I mentioned was actually COPY/FTP'ing the file in question to a linux box. My app on the linux side does check for complete files, but it seems that so far, the only thing that's saved me is the five-second wait-retry loop in the DCL script.

The whole intent of this is to get some info from the cluster to a database, and then to a web server; even a one-minute delay is acceptable...
hey ho, what do you know...
John Gillings
Honored Contributor

Re: Directory Change Notification - ODS-2/ODS-5

Beware!

The C code referenced will trigger whenever any process accesses the referenced directory in any way. That includes READ accesses. So, you'll get numerous false alarms. Make sure your code can cope with this.

Also, as Jan has pointed out, you'll get triggered when a file & consequent directory entry is *created*, not when it's closed. You need to work out a mechanism for synchronising reader and writer.

Note that exactly the same code (no mods required) can be used to block until a particular (non-directory) file is touched. That includes and read access, and also the creation of a new version. If your writer can be modified slightly - all it needs to do is open & close a specific file after it's generated the report, you can use activity on that file as the trigger for your reader.
A crucible of informative mistakes
Uwe Zessin
Honored Contributor

Re: Directory Change Notification - ODS-2/ODS-5

> F$FILE_AT(file,"LCK")

I don't see that LCK is a valid argument on V7.3-2 and "LOCKED" refers to 'deaccess locked' - a feature from RSX that locks the file when it was not properly closed.

You also need an error handler if you use:
F$FILE_ATT(file,"EOF")
because the lexical is aborted with an error status when the file is open for write.

$ open/write f file.dat
$ write sys$output f$file_attributes ("file.dat","eof")
%SYSTEM-W-ACCONFLICT, file access conflict
\file.dat\
$
$
$ close f ! don't forget this ;-)
.

Re: Directory Change Notification - ODS-2/ODS-5

F$FILE_ATTR(f, "EOF") can help...
In my case, the files I'm interested in have (very convenient) end-of-file magic numbers... say, a "--- 000 ---" string on a line by itself at the end of the file. I can run a search command, and check $SEVERITY...
hey ho, what do you know...
Antoniov.
Honored Contributor

Re: Directory Change Notification - ODS-2/ODS-5

Hi Oshadi,
f$file() function abort if file is locked by another use and you are not able to get any information. Here there is a little piece of code I used to retrive file allocation
$ IF F$TYPE(FAL).NES."" THEN DELETE/SYMB FAL
$ SET NOON !Avoid trap of error
$ DEFINE SYS$ERROR NLA0: !Avoid terminal msg
$ DEFINE SYS$OUTPUT NLA0:
$ FAL=F$FILE(FPN,"EOF")
$ DEASS SYS$OUTPUT !Restore msg
$ DEASS SYS$ERROR
$ SET ON !Restore trap
$ IF F$TYPE(FAL).EQS."" THEN GOTO SD03
It's just an example.
You can also use CDT (creation date) to know last created files.

Antonio Vigliotti
Antonio Maria Vigliotti
Peter Barkas
Regular Advisor

Re: Directory Change Notification - ODS-2/ODS-5

Newer version of the program referenced by Rob can be found at:

http://www.eight-cubed.com/downloads.html#watchdir
Richard W Hunt
Valued Contributor

Re: Directory Change Notification - ODS-2/ODS-5

As a variant thought...

If your application code is in any way subject to change, you would do better to have it send you something to notify you. Is the program run inside a shell that could detect its exit? Even if only the shell could be changed, that might be enough.

One method is to have it set an event flag in a Common Event Flag block. That would work pretty well if they are on the same system. This won't work all of the time if there is a cluster and the two processes could possibly run on different nodes.

Another method would be to create a mailbox in your application that needs to know when the file is created and have the application write the name of the new file to the mailbox. This would work in a clustered environment.

A third possibility involves some complex lock code, taking out an interest lock on the directory but allowing anyone to write to it anyway. You would need some AST-level code to note that someone wanted to update the directory and use that code to notify you when someone actually does change something.

The problem I see with repeated scans of your folder has to do with file system caches, least-recently-used schemes, and resultant performance degradation, albeit by a small amount. Your frequent scan of the folder will force the file system to keep that folder in your directory cache when you might have better uses for that memory. Particularly if it is a large (heavily populated) folder.

Making the file creator notify you will obviate the need for any scanning, which is a GOOD thing with respect to file system caches on a busy system.

Just a variant thought on how to make it work faster.
Sr. Systems Janitor

Re: Directory Change Notification - ODS-2/ODS-5

All good points... I'll take a closer look at the writer; it's possible that it would create a mailbox... but this writer process is created only when needed (once an hour for now), and exits in a few seconds (after the report generation).

Another application level solution might be possible: When all is said and done (i.e. the report generated, and the file is closed), the writer logs this in a central logfile like so:
"Created File: xxxxxxxx.LIS"

If I could just do a blocking read on this logfile... in DCL...
Otherwise I'd be polling this file doing Type/Page commands. As far as I can tell, DCL's READ is out? It write-locks the file even when it's been opened just for reading.
hey ho, what do you know...

Re: Directory Change Notification - ODS-2/ODS-5

> Type/Page

Drat, I meant Type/Tail :)
hey ho, what do you know...
Antoniov.
Honored Contributor

Re: Directory Change Notification - ODS-2/ODS-5

Hi,
you can control sharing access with /SHARE option of open statement.
See follow lines:
$ OPEN/REA/SHARE=WRITE SRC
Previous statement tells vms open file for read without lock.
However, if another process open file without permission like follow dcl command
$ OPEN/APPEND ...
no any other process can read file.

Antonio Vigliotti

Antonio Maria Vigliotti