# Unix-Script to count named-users

**URL:** <https://techcommunity.softwareag.com/t/unix-script-to-count-named-users/60164>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-Utilities\
**Created:** [September 14, 2005, 3:51pm UTC](https://techcommunity.softwareag.com/t/unix-script-to-count-named-users/60164 "2005-09-14T15:51:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelQ](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@MichaelQ](https://techcommunity.softwareag.com/u/MichaelQ)\
**Post date:** [September 14, 2005, 3:51pm UTC](https://techcommunity.softwareag.com/t/unix-script-to-count-named-users/60164/1 "2005-09-14T15:51:12Z")

</div>

Hi

Has anybody of You a Unix-script (shell doesn’t matter) which enables you to count the “named or concurrent user”, using Natural or Adabas?

To count Natural-user it should be possible to use something like “ps -ef | grep natural” to get the running natural-tasks and then using “awk” to get the user-ids out of the task-list.  
To count Adabas-user it should be possible to get the user out of the user-queue running the according Adabas-utility and then pipe it ro “awk”.

Therefore I’m not willing to build the scripts on my own :lol: I hope, that somebody has already these scripts and can pass it to me:([Michael.Quitsch@Softwareag.com](mailto:Michael.Quitsch@Softwareag.com)).

Thx and Greetings from Hambourg

Michael

---

<div class="post-metadata">

**Author:** ![anon29934956](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@anon29934956](https://techcommunity.softwareag.com/u/anon29934956)\
**Post date:** [September 14, 2005, 4:36pm UTC](https://techcommunity.softwareag.com/t/unix-script-to-count-named-users/60164/2 "2005-09-14T16:36:56Z")

</div>

Hello Michael,  
You may achieve the same when calling Natbpmon. You may even call natbpmon within Natural. Please refer to the code below, which has been written for Windows, but shall work with Unix after some modifications. 8)  
Sorry for my bad programming style :?

> [@](#):
>
> /\* program to get environment information  
> /\* MMR july 2005  
> /\*  
> /\* Requirements: work file 2 to write the report $TEMP$\nat-environment.txt  
> /\* to write to $TEMP$\natbpmon.bat  
> /\* to write to $TEMP$\xxx.txt  
> /\* USR1053N to read environment variable information  
> /\* USR1052N to call natbpmon.bat file  
> /\*  
> DEFINE DATA  
> LOCAL  
> 1 natini (A) dynamic  
> 1 natbpmonout (A) dynamic  
> 1 file (a) dynamic  
> 1 tempdir (a) dynamic  
> 1 batchfile (a) dynamic  
> 1 batch-command (a) dynamic  
> 1 outfile (a) dynamic  
> 1 status (a) dynamic  
> 1 parm (A) dynamic  
> 1 who (a) dynamic  
> 1 natdirvers (a) dynamic  
> 1 line (a70) init \<‘--------------------------------------------------------’\>  
> 1 output (a) dynamic  
> 1 USR1053L  
> 2 INPUTS  
> 3 ENV-VARIABLE (A80)  
> 2 OUTPUTS  
> 3 CHAR-STRING (A253)  
> 3 RESPONSE (I04)  
> 1 USR1052L  
> 2 OS-COMMAND (A253)  
> 2 RESPONSE2 (I04)  
> 1 #FLAG (A1)  
> 1 #SYNCHFLAG (A1)  
> END-DEFINE
> 
> /\* define page size  
> FORMAT LS=120 PS=40
> 
> /\* --------------------------------------------------------  
> /\* define output file for report C:\temp\nat-envrionment.txt  
> /\* --------------------------------------------------------  
> define work file 2 “C:\temp\nat-environment.txt” type “unformatted”
> 
> /\* --------------------------------------------------------  
> /\* display environment variables using USR1053  
> /\* --------------------------------------------------------  
> compress ‘Natural Environment Information’ h’0d0a’ line h’0d0a’  
> \*DATE \*TIME \*USER h’0d0a’ line h’0d0a’  
> ‘Environment Variables’ h’0d0a’ line h’0d0a’ to output  
> ENV-VARIABLE := ‘NATDIR’  
> CALLNAT ‘USR1053N’ USR1053L  
> if response \<\> 0 then  
> compress output ‘NATDIR not defined’ h’0d0a’ to output  
> else  
> compress output ‘NATDIR ‘char-string h’0d0a’ to output  
> move char-string to natdirvers  
> end-if  
> ENV-VARIABLE := ‘NATVERS’  
> CALLNAT ‘USR1053N’ USR1053L  
> if response \<\> 0 then  
> compress output ‘NATVERS not defined’ h’0d0a’ to output  
> else  
> compress output ‘NATVERS ’ char-string h’0d0a’ to output  
> compress natdirvers ‘' char-string into natdirvers leaving no  
> end-if  
> ENV-VARIABLE := ‘FUSER’  
> CALLNAT ‘USR1053N’ USR1053L  
> if response \<\> 0 then  
> compress output ‘FUSER not defined’ h’0d0a’ to output  
> else  
> compress output ‘FUSER ’ char-string h’0d0a’ to output  
> end-if  
> compress output line h’0d0a’ ‘End Environment Variables’ h’0d0a’  
> line h’0d0a’ to output
> 
> /\* ---------------------------------------------------------  
> /\* get natbpmon statistik  
> /\* ---------------------------------------------------------  
> compress output ‘Natural Buffer Pool Information’ h’0d0a’  
> line h’0d0a’ to output
> 
> /\* write os-command into batch file  
> compress tempdir ‘\natbpmon.bat’ to batchfile leaving no  
> define work file 3 batchfile type “unformatted”  
> compress ‘"’ natdirvers ‘\bin\natbpmon.exe"‘to batch-command leaving no  
> compress tempdir ‘\xxx.txt’ to outfile leaving no  
> compress batch-command ‘param \>\>’ outfile to parm  
> compress batch-command ‘who \>\>’ outfile to who  
> compress batch-command ‘status \>\>’ outfile to status  
> compress ‘echo PARAM \>’ outfile h’0d0a’ parm h’0d0a’  
> ‘echo WHO \>\>’ outfile h’0d0a’ who h’0d0a’  
> ‘echo STATUS \>\>’ outfile h’0d0a’status h’0d0a’ to batch-command  
> EXAMINE batch-command FOR ‘"’ AND REPLACE WITH H’22’  
> write work 3 variable batch-command
> 
> /\* close batch file and open output file  
> define work file 3 outfile type “unformatted”  
> /\* execute batch file  
> compress batchfile to os-command  
> CALLNAT ‘USR1052N’ USR1052L  
> if response \<\> 0 then  
> compress output h’0d0a’ ‘Return code from the operating system:’  
> RESPONSE2 h’0d0a’ to output  
> end-if
> 
> /\* read output file  
> read work 3 natbpmonout  
> compress output h’0d0a’ natbpmonout h’0d0a’ to output  
> end-work  
> compress output line h’0d0a’ ‘end Natural Buffer Pool Information’  
> h’0d0a’ line h’0d0a’ to output
> 
> write work file 2 variable output  
> END

---

<div class="post-metadata">

**Author:** ![MichaelQ](https://avatars.discourse-cdn.com/v4/letter/m/ecccb3/32.png) [@MichaelQ](https://techcommunity.softwareag.com/u/MichaelQ)\
**Post date:** [September 15, 2005, 4:25pm UTC](https://techcommunity.softwareag.com/t/unix-script-to-count-named-users/60164/3 "2005-09-15T16:25:20Z")

</div>

Hi Michael

First of all: Thanks for Your help !!!  
Very interesting Natural-Prog. I tried it in my environment and it worked very well. But there is one problem left:

How can I count named Users? Or ist it possible to count them?

The bufferpool always shows me the number of concurrent users. But to show the number of concurrent user it is easier to run:

ps - ef | grep natural | wc -l

From the result you have to subtract -1 because the grep is also counted.  
So, is it possible to get the number of named users (based on the used UserIDs) from the natbpmon?

When calling

“natbpmon who”

I’m getting the following result :

Bufferpool version 1.3(435) of 27-NOV-1997 12:24:59  
index | tid  
------±-----------------------------------------------------------------------  
1 | sag 27336  
2 | mq /dev/pts/0 4251

So, I have to use awk, to get the user out of the list :?  
Or I can pipe it in a file for further analyses.

At the end I must say, that my question was a little bit “stupid” :oops:  
Therefore telnet does not route the tcp/ip-address of a PC a user is using for emulation and several users may use the same userid it would be only possible to document used userids but it is not possible to count “named user”.  
☹ :?

Mhhh?!?!? But This is also an answer. :shock:

Greetings

Michael

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [September 16, 2005, 4:01pm UTC](https://techcommunity.softwareag.com/t/unix-script-to-count-named-users/60164/4 "2005-09-16T16:01:25Z")

</div>

Please note that it looks that the “natbpmon who” command(process) itself is included in the listing.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:40pm UTC](https://techcommunity.softwareag.com/t/unix-script-to-count-named-users/60164/5 "2021-04-02T14:40:16Z")

</div>


