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

UNIX procedure equivalent in OVMS?

SOLVED
Go to solution
Andrew Yip
Advisor

UNIX procedure equivalent in OVMS?

Hello!
I'm a newbie to VMS scripting and i would greatly appreciate if someone would offer me some solutions here.

I've been trying to perform the following procedure in OpenVMS as i've done well in UNIX.

foreach file (`ls `)
mem del $file
end

What exactly i'm trying to do here is to capture a list of existing files in a specified directory and delete those same files residing in a connected industrial machine. The statement "mem del" is basically delete files in the machine's memory.

On top of this, there's another problem with VMS. I noticed when i performed a "directory" command on a location. All the files comes with a version number at the end. This would pose a problem when i try to use the filenames to delete in my machine's memory. In this case, i would need to truncate the trailing version numbers.

How can i get these done with similar commands which i'd used in my UNIX script? Please help....please?!

Augustine Andrew
23 REPLIES
Uwe Zessin
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

The mechanism to loop over files in a directory is by using a "lexical function" named F$SEARCH():

-----
$LOOP:
$ FNAM = F$SEARCH ("*.*;*")
$ if FNAM .eqs. "" then $ goto DONE
$! delete 'FNAM'
$ write SYS$OUTPUT FNAM
$ goto LOOP
$DONE:
$ exit
-----

> All the files comes with a version number at the end. This would pose a problem when i try to use the filenames to delete in my machine's memory.

You MUST specify a version number (or the "*" wildcard) in order to be able to delete a file.


> i would need to truncate the trailing version numbers.

In case you need this for something else - use:
$ directory *.*; /select=file=noversion /column=1
.
labadie_1
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

I am not sure there is a Vms equivalent of "mem del".

If you want to check the files in a directory, use f$search, and you can check the help with
$ help lexical f$search

an example
$ loop:
$ file = f$search("my_directory:*.dat")
$ if file.eqs."" then exit
$ !your code about that file, here a search (grep in Unix) ...
$ search 'file my_string
$ goto loop:

With f$search, if you do several concurrent searches, you will use the stream id (here 1 and 2)

$ START:
$ COM = F$SEARCH ("*.COM;*",1)
$ DAT = F$SEARCH ("*.DAT;*",2)
$ SHOW SYMBOL COM
$ SHOW SYMBOL DAT
$ IF (COM.EQS. "") .AND. (DAT.EQS. "") THEN EXIT
$ GOTO START
Mike Reznak
Trusted Contributor

Re: UNIX procedure equivalent in OVMS?

Hi,

to get only the file name for use in remote specification use F$PARSE. [may be omit the version]

FNAMSHORT = f$PARSE(FNAM,,,"NAME") + f$PARSE(FNAM,,,"TYPE") [ + f$PARSE(FNAM,,,"VERSION") ]

Mike
...and I think to myself, what a wonderful world ;o)
Jan van den Ende
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

Andrew,


residing in a connected industrial machine. The statement "mem del" is basically delete files in the machine's memory.

The way I interpret your question: "at the VMS system there is a directory in which files reside, copies of which exist in the memory of the connected machine".

If so:
- what is the OS of those machines?
- do you just need to remove the memory copies, or also the VMS files?

How to get the list of files is by any of the given methods.
If you just beed a list, I would use the last line given by Uwe, perhaps with the addition of /NOHEADER and /NOTRAILER.
Put that in a file ( /OUTPUT= filename ). or use PIPE, to feed your original example.

If you also want to delete the VMS file, then use the file mechanism. You have to add the version number again (use wildcard, ;* ) for a VMS DELETE.
If there is no need to remove both synchronously, use the PIPE method, and for VMS just delete the whole bunch at one go: DELETE *.*;*

hth,

Success

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Andy Bustamante
Honored Contributor

Re: UNIX procedure equivalent in OVMS?


You can also select files with

$ delete /before=
If you don't have time to do it right, when will you have time to do it over? Reach me at first_name + "." + last_name at sysmanager net
Andrew Yip
Advisor

Re: UNIX procedure equivalent in OVMS?

Hey guys!

Wow! This is like family! What prompt response we have here?! You guys are great!
But anyway, i still have some problems after trying out your wonderful suggestions.
============================================
Hi Uwe,
Your idea works. But i've a problem when i need to delete the list of files generated by the F$SEARCH function in a different directory. FNAM returns the full directory path of the search list. Hence, i wouldn't be able delete the same files in any other directory other than the original search location. Do you have a fix on this small glitch?

On the other hand, your truncation method doesn't work on my machine.It seems like mine doesn't support the 'file' keyword.
*[%DCL-W-IVKEYW, unrecognized keyword - check validity and spelling
\FILE\]

How do i check the version of my OVMS for scripting compatibility? I felt that my OVMS's scripting language works a little different. Hmm...strange!
============================================
Hi Labadie,
Thanks for your ideas too!
"Mem Del" is not a OVMS command, it's my other machine's command. It doesn't matter.
Thanks!
============================================
Hi Mike,
Thanks for your command there although i don't understand it.
The command line works for me, but it returns an error msg when i invoke it.
*[%DCL-W-SYMDEL, invalid symbol or value delimiter - check command syntax]
What is this all about?
============================================
Hi Jpe,
Yes, you've got my point.
The OS of my connected machine doesn't matter. It's making use of OVMS to communicate with it. I only need to delete the memory copies in that machine using the "mem del" command. No issues with that.

Sorry, i may sound stupid but how do i utilize the /NOHEADER & /NOTRAILER qualifiers to Uwe's command?

/OUTPUT doesn't seemed to work on my OVMS. My OVMS works a little different from others, i think.
============================================

Best Regards,

Andrew

Joseph Huber_1
Honored Contributor
Solution

Re: UNIX procedure equivalent in OVMS?


Your alter ego on computing.net specified a bit more precisely that You have VMS 5.5 !
And in this ANCIENT version there was rarely a /output qualifier for commands.

So You have to redirect output of the dir command by
define/user sys$output somename.tmp
dir ...
to achieve the same as dir/output=somename.tmp .

And as I have said in computing.net, parse the file-specification into nt=name+type, then
delete thedisk:[thedirectories]'nt';*

http://www.mpp.mpg.de/~huber
Kris Clippeleyr
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

Andrew,

Attached command procedure works for me.
Note that I haven't tested it thoroughly.

Regards,
Kris (aka Qkcl)
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
Jan van den Ende
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

Andrew,

So, VMS 5.5, and the procedure runs on VMS, to operate on the remote system, and the directory over there is different (say: remdir)
(supposing MEM DEL is doing the same as on *X:)

$ DEFINE SYS$OUTPUT DIRLIS.TMP
$ DIRE /NOHEADER/NOTRAIL/COL=1
$ OPEN IFI DIRLIS.TMP
$LOOP:
$ READ IFI FIL /END=DONE
$ REMFIL = + F$PARSE(FIL,,,"NAME") + F$PARSE(FIL,,,"TYPE")
$ MEM DEL 'REMFIL'
$ !? DELETE 'FIL' !? maybe local del as well?
$ goto loop
$DONE:
$ CLOSE IFI
$ DELETE DIRLIS.TMP.*


hth

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Andrew Yip
Advisor

Re: UNIX procedure equivalent in OVMS?

Thanks! Your ideas work well!

Jpe,

Your method works faster than having to use the f$search and IF-THEN-ELSE statements.

By the way, how do i append my next output when applying the define method?

E.g:

DEFINE SYS$OUTPUT test.log
show time
DEASSIGN SYS$OUTPUT
Uwe Zessin
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

That's not possible, I think, but:

$ define sys$output time.tmp
$ show time
$ deassign sys$output
$ append time.tmp test.log
%APPEND-W-INCOMPAT, USER_1:[ZESSIN]TIME.TMP;1 (input) and USER_1:[ZESSIN]TEST.LOG;1 (output) have incompatible attributes
$ delete time.tmp;
$ type test.log
abc
___5-DEC-2005 07:55:59
$


Another idea:

$ open /append t_log test.log
$ write t_log " "+f$cvtime(f$time(),"absolute")
$ close t_log
$ type test.log
abc
___5-DEC-2005 07:55:59
__5-DEC-2005 07:59:51.50
$

(I have replaced the leading spaces in the file output with underscores "_" to better illustrate the difference, because ITRC eats spaces :-(
.
Joseph Huber_1
Honored Contributor

Re: UNIX procedure equivalent in OVMS?


Your method works faster than having to use the f$search and IF-THEN-ELSE statements.


Although it has nothing to do with the original question,
but this statement sounds unjustified.

Writing the output of a command to a file, then reading it is clumpsy as long as there is an equivalent function built into DCL like in this case DIRECTORY/OUTPUT vs. f$search.

And why creating a file,invoking an image, opening and reading a file should be faster than DCL-internal directory search is beyond my imagination.

Could You explain how You measured it being faster ?

Directory output to a file is IMHO only needed, if some /EXCLUDE or other criteria can't be achieved easily inside DCL, or if the file list has to be sorted somehow.
http://www.mpp.mpg.de/~huber
Karl Rohwedder
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

Joseph,

I've just compared a simple F$SEARCH loop finding 200 files with a DIR /OUT and reading its output: the DIR solution is faster:

- is uses less CPU and elapsed time and BufIO
- is needs more hard faults and DirIO

Normally I would prefer the DCL F$SEARCH solution, because you are not dependant on the format of the DIR output.

regards Kalle
Jan van den Ende
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

Kalle,


- is uses less CPU and elapsed time and BufIO
- is needs more hard faults and DirIO


Remove Elapsed Time from these lines, and it means, that the amouts of Elapsed Time are configuration-dependant. Much CPU power and Memory favors the DIR solution, good Caching and fast disk IO favors the F$SEARCH.

-- although whenever possible a personally favor lexical function solutions over output-parsing!

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Joseph Huber_1
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

Interesting !
I made tests with my slowest and fastest CPUs, and it seems that only for short (few hundreds) number of files DIRECT/output wins. In all other cases f$search loops are faster, and gain with the number of files.
Seems that f$search has a bigger 'pedestal' at initialization.
http://www.mpp.mpg.de/~huber
Joseph Huber_1
Honored Contributor

Re: UNIX procedure equivalent in OVMS?


And one additional note on the differences:

DIRECTORY lists ALIAS files/directories,
f$search does not return aliases !

So it may well make a difference wether the list of files is for processing or e.g. for delete/remove.
http://www.mpp.mpg.de/~huber
Uwe Zessin
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

Can't speak for VAX, but on OpenVMS Alpha V7.3-2 it lists aliases - no matter if the primary entry is in the same or a different directory.
.
Joseph Huber_1
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

Maybe I was a bit unclear:
if You explicitely do f$search("[.dir]*.*"), then yes, it returns files wether being aliases of some files in other directories.
But say You have [.a] and [.b] being an alias directory of [.a], then f$search [...]*.* returns the files only once, not the files in [.b].
http://www.mpp.mpg.de/~huber
Joseph Huber_1
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

Sorry , forget my previous statement.
Uwe is right, I had by chance exactly as many files to purge as I had aliases resulting in the same difference of number of files between
f$search() and DIRECTORY.

So not the alias behaviour is different, but

f$search("*.*") is not the same as
directory *.*

the directory command defaults to version ";*" if not explicitely version 0 (";" or ";0") is specified, while f$search("*.*") returns only the highest version.
http://www.mpp.mpg.de/~huber
Jan van den Ende
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

Joseph,

slight addendum:

f$search CAN find all versions of files, but for that you have to explicitly specify ;*

So, the default for DIR is ALL versions, you have to specify ;0 for the highest, while the default for f$search is the highest version, you have to specify ;* for all.

And of course, BOTH support ;-1 etc for the second highest etc, and ;-0 for the LOWEST version.

hth

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Andrew Yip
Advisor

Re: UNIX procedure equivalent in OVMS?

Hmm...in this case, how do you append command outputs to a file the way UNIX does?

E.g.
%date >> test.log
%pwd >> test.log
%cat test.log
/export/home/user
Tue Dec 6 08:58:01 singapore 2005

Uwe,
your method would require the outputs to be in seperate files 1st before appending them into 1 file right?

Is there a way to perform the append function simliar to the above UNIX method?
Karl Rohwedder
Honored Contributor

Re: UNIX procedure equivalent in OVMS?

The >> is currently not supported on VMS, you can e.g. with contructs such as:

$ pipe cmd > append sys$pipe: file

The > Operator always creates a new file.

regards Kalle
Andrew Yip
Advisor

Re: UNIX procedure equivalent in OVMS?

Kalle,

I can't use your method.
My VMS version 5.5-2 doesn't allow that.