Operating System - OpenVMS
1748180 Members
4314 Online
108759 Solutions
New Discussion юеВ

Re: awk, external command and quotes

 
SOLVED
Go to solution
Sheldon Smith
HPE Pro

Re: awk, external command and quotes

FYI: With judicious use of quotes, you can do useful things directly from DCL *without* a secondary script file. The trick is understanding when to 'escape' a quotation mark, and when to double it. Or both. 8^)
Here are a couple 'one-liners' from my collection:

Initialize any disks that have *never* been initialized:
------
pipe sho dev dg | gawk "BEGIN {print ""$set noon""}; /Online/ {print ""$mou /over=id /noassi"", $1; print ""$if f$mess( $status, \""ident\"") .eqs. \""%NOHOMEBLK\"" -""; print "" then init/sys /limit"", $1, ""UNUSED""}" sys$pipe: | @sys$pipe:

Show the size of all locally mounted disks (in MB):
------
pipe show dev d/mou | GAWK "/Mounted/ && !/(remote mount)/ {print ""$ write sys$output \"""" $1 ""\t\"", f$getdvi( \"""" $1 ""\"", \""maxblock\""), \"" bl.\t\"", f$getdvi( \"""" $1 ""\"", \""maxblock\"")/2048, \"" MB\""""}" sys$pipe: | @sys$pipe:

Note: While I am an HPE Employee, all of my comments (whether noted or not), are my own and are not any official representation of the company

Accept or Kudo

labadie_1
Honored Contributor

Re: awk, external command and quotes

Sebastian

I am not sure I understand: I have a variable number of BG devices, say 50, so passing a pid will not help

Sheldon

Thanks a bunch for the procedures, I will have a close look
Sebastian Bazley
Regular Advisor

Re: awk, external command and quotes

Sorry, missed that part of the thread.

However you could join the pids (e.g. with a comma) if you wanted, and then split them again...

Or of course, put the raw pid details in a file that is read by the awk script.
labadie_1
Honored Contributor

Re: awk, external command and quotes

I have attached the last version of my awk script.

It defines some symbols
- statbyr
sorts the BG Devices by Bytes received
- statbys
sorts the BG Devices by Bytes sent
- statior
sorts the Bg devices by I/O received
- statios
sorts the Bg devices by I/O sent

It is highly inefficient, as I do
for (bg in prcnam)
if (bg == toupper(dev))
printf ...

So if I have 200 bg devices, I will be 200x200 times in this loop

I have been surprised to discover that without the line
for (bg in prcnam), I do not find any array member.

Some with a higher knowledge of awk may explain it.

Hein van den Heuvel
Honored Contributor

Re: awk, external command and quotes

Wow, that's just horrible.

1)
What's the tolower doing in "if (/^Device/) {tolower" ?
Did you mean:
if (/^Device/) {split (substr($2,1,(length($2)-2)),x,","); bg=tolower(x[1]) ;}

And is that substr stuff just to get of the ":"?
Then just split on that!
if (/^Device/) {split $2,x,":"); bg=tolower(x[1]) ;}


2)
... dev=toupper($2)
:
for (bg in prcnam)
if (bg == toupper(dev))

Is that second 'toupper' 'just in case the first one did not work?'

I think all you need is: bg = dev .. but at a place where all the other data is collected. I don't have a system with 'ucx shwo dev/full' available right not.
But let's assume 'Bytes transferred' is the last line.
In that case the solution show be:

/Bytes transferred/ {byt = 0 ; byt=$3 ; byr= 0 ; byr=$4 ;
bg = dev;
printf(...)
}

3) Should the printting of the header line (print("device... ) not be part of the BEGIN {} block?

4) Why 'awk' 4 times for 4 sort orders?
The data could change?! awk once, sort 4 times! Append to header lines after each sort.


Cheers,
Hein.




labadie_1
Honored Contributor

Re: awk, external command and quotes

Hein wrote
>>>Wow, that's just horrible.
Yes, I concur
:-)

>>>1)
What's the tolower doing in "if (/^Device/) {tolower" ?

the bg device in the first list (with the pid) and the second list are one in uppercase and the other in lowercase, so the test failed

>>>And is that substr stuff just to get of the ":"?
yes, because comparing bg227 and bg227: will fail :-)

Then just split on that!
if (/^Device/) {split $2,x,":"); bg=tolower(x[1]) ;}


2)
... dev=toupper($2)
:
for (bg in prcnam)
if (bg == toupper(dev))

>>>Is that second 'toupper' 'just in case the first one did not work?'
I forgot this one.

>>>I think all you need is: bg = dev .. but at a place where all the other data is collected. I don't have a system with 'ucx shwo dev/full' available right not.
But let's assume 'Bytes transferred' is the last line.

Yes it is
In that case the solution show be:

/Bytes transferred/ {byt = 0 ; byt=$3 ; byr= 0 ; byr=$4 ;
bg = dev;
printf(...)
}

3) Should the printting of the header line (print("device... ) not be part of the BEGIN {} block?
May be, but anyway I want it at the back of the display, because I sort with the higher values at the end.

4) Why 'awk' 4 times for 4 sort orders?
The data could change?! awk once, sort 4 times! Append to header lines after each sort.

Yes of course

Thanks for your inputs.
labadie_1
Honored Contributor

Re: awk, external command and quotes

I have done as you said, as Bytes transferred is the last motif searched

>>>But let's assume 'Bytes transferred' is the last line.
In that case the solution show be:

/Bytes transferred/ {byt = 0 ; byt=$3 ; byr= 0 ; byr=$4 ;
bg = dev;
printf(...)
}

And I no longer have the pid and prcnam.

There is something I have not understood in the flow of data in awk...

:-(
Hein van den Heuvel
Honored Contributor

Re: awk, external command and quotes

I suspect there is still a slight punctuation error on the device name.

Print them out for a debug run, may on 1 device?

Email me a sample SHOW DEV BG/FULL as well as a sample UCX SHOW DEV/FULL and I'll see if I can find time to cehck it.

Flow in AWK is a surprise for first time users.
The main flow is 'all code' for all record in the input.
The /something/ {block} construct is really an 'if ($0 look like something) then {block}'

Most awk programs have simple {} block with no conditional, making that run for every line.

You can add a BEGIN {} and END {} which run jsut once typically to setup, print header fin BEGIN, and to print a total in END.

Cheers,
Hein.

labadie_1
Honored Contributor

Re: awk, external command and quotes

Hein

I have emailed you the various files.
Thanks for your time.

I am trying to debug.
labadie_1
Honored Contributor

Re: awk, external command and quotes

Thanks to Hein, the procedure now displays the pid and processname for each bg, without looping too much :-)

It is available at
http://dcl.openvms.org/stories.php?story=07/06/04/4359262