cancel
Showing results for 
Search instead for 
Did you mean: 

DCL

 
Highlighted
Advisor

DCL

could some one tell how to pass a command output
to an variable

I shall be thank full if you share some DCL scripting guide/book/document

thanks
11 REPLIES 11
Highlighted
Honored Contributor

Re: DCL

Bjay,

The simplest way to get the output of a command to a place where it can be read and analyzed is to use the ASSIGN/USER_MODE to route the logical name SYS$OUTPUT to a temporary file.

For an introduction to logical names, see "Logical Names (Part 1)", part of The OpenVMS Consultant series of columns on OpenVMS.org (see http://www.openvms.org/gezelter ).

The "DCL Dictionary" manual is available on the OpenVMS www site at http://h71000.www7.hp.com/doc/83final/9996/9996pro.html

- Bob Gezelter, http://wwws.rlgsc.com
Highlighted
Honored Contributor

Re: DCL

You're not on Unix, and OpenVMS DCL redirection is comparatively weak. And there are some wrinkles here between DCL symbols and logical names, and subprocesses.

In general, this doesn't work. Symbols are "bigger" on recent OpenVMS releases, but not big enough to contain the output from many DCL commands.

The OpenVMS User's Guide is the manual you want to read here. This is in the OpenVMS documentation set.

http://www.hp.com/go/openvms/doc

That material will help you understand symbols and logical names and how to deal with /OUTPUT qualifiers and command redirection and such.

The OpenVMS Frequently Asked Questions (FAQ) has how to pass command output around using the PIPE command and logical names. There's a copy of the FAQ here:

http://www.hoffmanlabs.com/vmsfaq/

There's another book around, _Writing Real Programs in DCL_ by Paul Anagnostopoulos and somebody named Hoffman, but that book is presently out of print and used copies of the second edition are reportedly expensive. It's now conceivable that this book might come back into print if there's enough demand, though not through the fine folks over at the Elsevier Digital Press imprint; the previous publishers.

Highlighted
Honored Contributor

Re: DCL

You may want to describe the specific problem you want to address. As replied above, there is no common, single solution. Many folks parse file output, several commands having a /OUT qualifier. Some commands leave DCL symbols (SEARCH) to use. Some use a PIPE construct to snarf output and put it into a logical name.

But most importantly you need to realize that often you do NOT need a command. DCL has a set of powerful LEXICAL to do what on other platforms (Unix) is done using a command.
For example, check out HELP LEXI F$SEARCH as a (better!) alternative to capture the DIRECTORY command output. Ans G$GETDVI and F$FILE and so on.... Check HELP and... RTFM!

Hein.
Highlighted
Honored Contributor

Re: DCL

Try using the "PIPE" command. For example, consider the command;

$ dir/size=all/grand [...]*.*.*

Grand total of 38 directories, 697 files, 26981/71686 blocks.

Now lets say you want to assign the #of files and total blocks to symbols to use within a script. If P1 is the directory listing ("[...]*.*.*"), then the following command will define the symbols; NFiles = "number of files", and NBlks = Total Blocks.

$ Pipe Dir/Size=all/grand 'P1' | (Read Sys$Input Line ; Read Sys$Input Line ; -
Files = f$elem(5," ",Line) ; -
Blks = f$elem(1,"/",f$elem(7," ",Line)) ; -
define/job/NoLog Nfiles &files ;-
define/job/NoLog Nblks &blks)
$ Nfiles == F$TrnLnm("NFiles","Lnm$Job")
$ NBlks == F$TrnLnm("NBlks","Lnm$Job")

Its a bit clunky, but it is very flexible.

Dave.
Highlighted
Honored Contributor

Re: DCL

Dave's PIPE example but done in PERL ...

$ perl -e "for (qx(dir/size=all/grand *.*)){ if (/(\d+) fil.*\/(\d+)/) { $ENV{files}=$1; $ENV{blocks}=$2}}"

$ show log files, blocks
"FILES" = "514" (LNM$PROCESS_TABLE)

"BLOCKS" = "421728" (LNM$PROCESS_TABLE)
$


Same thing using those LEXICALS and a DCL loop:

-----------------------
$files == 0
$blocks == 0
$loop:
$ file = F$SEARCH ("*.*;*")
$ IF file .EQS. "" THEN EXIT
$ files == files + 1
$ blocks == blocks + F$FILE(file,"ALQ")
$ GOTO loop
--------------------------


$SHOW SYMBOL files ...

fwiw,
Hein.


Highlighted
Honored Contributor

Re: DCL

> You're not on Unix, [...]

I agree. On UNIX, it often makes sense to
use the `` or $() notation in a script to
collect the output from some command. On VMS
it seldom does. DCL has lexical functions
which can be used in expressions, and these
are more often the better way to do things.

For example, on UNIX, one might try to parse
"df" output to find the free space on a file
system. On VMS, it makes little sense to try
the same thing with SHOW DEVICE /FULL output
when the F$GETDVI lexical function can do it
easily:

alp $ write sys$output f$getdvi( "dka0:", "freeblocks")
16733466

> You may want to describe the specific
> problem [...]

Another good idea. Asking how to implement a
particular poor solution to a problem is
often less useful than asking how to solve
the actual problem.
Highlighted
Advisor

Re: DCL

here is what I am doing

1. I have a recording of monitor system command which is taken after every 5 mins
$

and this output is stored into files with time stamp in there name

2. I have to generate a report of last one week disk IO's
so I create a list of monitor record files into a list file
$ dir /since= /before= /column=1 /out=dir.lis

3. then I read this file line by line and parse it to monitor command

$ open /read rec dir.lis
$ rdloop:
$ read /end_of_file=endit rec val
$ define /user sys$output monrep.out
$ pipe monitor disk /input='val | sea sys$input dka0
$ goto rdloop
$ append monrep.out;* monrep.report

4. then I read the monrep.report file and fetch out the desired information
$open /read inpt monrep.report
$ read /end_of_file=clsit inpt val2
$ val2=f$edit(val2,"compress,trim")
$ dsk=f$element(0,"",val2)
$ ios=f$element(4,"",val2)

QUERY
========
IN STEP 3 WHERE I AM DEFINING THE OUTPUT TO A FILE TO WRITE TO THE FILE IS THERE OTHER WAY TO DO THAT
Highlighted
Valued Contributor

Re: DCL

I'd have thought it would be easier to simply run MONITOR/RECORD contionuously and then pull out the statistics you want with a MONITOR/INPUT

Unless I misunderstood what you are trying to achieve....

Craig
Highlighted
Advisor

Re: DCL

these monitor recording files are of past we want to analyze the IO data of past