0

I have a jobm in SAG Natural, that creates workfiles. After they are created I want to append if there are multiple and then ftp them. The append/ftp would be run independently of the job that creates them. This poses the problem of trying to ftp/append a file while it is currently being created.

Is there any syntax in OpenVMS or in FTP that can check to see if a file is open/locked before I continue on with my logic?

Joey
  • 3
  • 3
  • Do you know the sharing status of the file? If it doesn't allow shared write then you could try to open it for writing (DCL `OPEN/WRITE`). That will fail if the file is open. – HABO Apr 06 '16 at 14:09

2 Answers2

1

I would NOT try open for write... because it may work, lock out others, and change the revision date/count. Instead just try $OPEN/READ/SHARE=READ FILE ...

If it opens, you can actually use the file handle to read the data, thus preventing an other process from (re-)opening it between the test and usage. But it will be using DCL IO which uses a small buffer. The example below shows this for mostly for fun: APPEND FILE ... The example hard-codes an output mostly because I was lazy. You are better of just closing the file on success first and then use the APPEND/LOG.

Enjoy, Hein

$ output = "tmp.tmp"
$ if p1.eqs."" then exit 16
$ create tmp.tmp
$ old = ""
$loop:
$ file_name = f$search(p1)
$ if file_name .eqs. "" .or. file_name .eqs.old then exit
$ old = file_name ! Handle non-wildcarded input
$ close/nolog file
$ open/read/share=read/erro=locked_or_other_error file 'file_name'
$ append file tmp.tmp ! /log
$ write sys$error "Appended ", file_name
$ close/nolog file
$ goto loop
$locked_or_other_error:
$ write sys$error "Found, but could not open file ", file_name
$ goto loop
Hein
  • 1,453
  • 8
  • 8
0

Does SHOW DEVICE /FILE help? If your file is open, it should show up in the output of that command.

user2116290
  • 1,062
  • 5
  • 6
  • in a Cluster that would be `mc sysman set env/clu` followed by `do pipe sh dev /fil disk | search sys$pipe file` we lack inotify in OpenVMS – user2915097 Apr 07 '16 at 10:01