Rocket U2 | UniVerse & UniData

 Command to see what account a tty is logged into

kathleen hambrick's profile image
kathleen hambrick posted 10-05-2021 14:43
Does anyone know a linux or Unidata command to see what account each user is currently logged into?

Thanks!
Tom VanKirk's profile image
Tom VanKirk
On our AIX Unix Unidata 8.2.2 instance:

:WHERE
/dp/app1/KMC
:
:ED VOC WHERE
Top of "WHERE" in "VOC", 2 lines, 7 characters.
001: V
002: WHERE
Tom VanKirk's profile image
Tom VanKirk
You could create a script to access fuser VOC in the account and back track each PID to the users listed, take a bit though.

root@prod:/prod/apps/KMC> fuser VOC
VOC: 14680180 14811358 14876692 15794404 15925294 15990976 16122088 17367240 18088100 18153624 18219188 18415656 18612342 18874588 18939958 19398868 19464346 19857532 20447312 20709540 21102764 21823606 22413408 22479092 22544634 22806778 23527428 24117494 24182860 24313990 24445086 24510508 24838200 25034986 25100520 25165866 25297104 25559160 25690336 25821394 27000884 27328750 27852870 28115068 28311744 28377158 28836058 28901418 29163682 29425910 29556922 29753396 29819072 30146650 30867566 31064188 31457368 31523030 31785054 32309344 32899166 33095868 33161306 33554660 33685730 34078798 34406546 34603184 34799808 35061796 35258574 36372662 37027968 37290166 37355718 37552334 38273172 38338750 38469784 39190604 39649314 39780376 39845932 39911542 40108254 40763460 41091166 41615480 41680928 42205192 42402008 42926100 43384928 43581630 43647224 43778072 43974804 44302490 44761248 45940806 46137474 46858264 46989448 47251476 49086512 49741942 50331738 50397352 51249264 51708086 51839174 52166848 52232264 52428968 52560114 53149770 53412056 53477410 53543094 53936130 54001822 54067404 54853634 55115832 55312472 55509196 56164356 56295624 56754418 57082034 57213078 57540664 57999588 58065082 58261642 58523780 58589352 58785922 59572286 59899930 60162052 60358878 61014192 61341836 61407320 61997156 62259378 62914756 63439034 63701106 63832180 64094248 64291062 65208324 65274048 65667100 66322498 66715764 66781372 66846768 197070 262496 917824 1704276 2163178 2294228 2621820 2752822 2949596 3015014 3473718 3539226 3735876 3932544 3997964 4391206 4653366 4784524 4850094 4981048 5046558 5243318 5964178 6685034 6816162 7274828 7733532 8258040 8454544 8520160 8585636 8782154 8847742 9568740 10158504 10289478 10420702 10617130 10682662 10813770 11010384 11141384 11207034 11338178 11928002 12058962 12321254 12386674 12648736 12845516 12911038 13238656 13566406 13631894 13762902 13959428 14024980 14156120 15073660 15663444 15728938 16122188 16318924 16843082 16974082 17039692 17170922 17236356 17564158 17891612 18350584 18612724 19136942 19333578 19464494 19792246 19923434 20447730 20971958 21037556 21299614 21496106 21758440 21823874 22282656 22675868 22806938 23069050 23527726 23658916 23789996 24183206 25035092 25297366 26083802 26476970 26608076 27001258 27132170 27459898 27787652 28180850 28311840 28443048 28574004 28967202 30278138 30343492 30605662 30671246 30998942 31392052 31654374 31916290 32047398 32506310 32637286 33227052 334237
54 33620350 33882392 34668938 34799996 35520876 35979772 36110688 36241722 36438356 36569478 36700560 36831742 37159392 37421484 37552536 37683496 37945778 38076766 38338900 38666738 38928708 39125472 39191000 39321864 40698192 40960382 41550274 42795432 42926500 43123068 43254020 44106098 44171742 44695832 44892480 45613418 45941114 46072092 46137602 46203304 46661988 46793132 46858624 46989712 47120724 47251914 47317422 47382976 47907196 48496964 48824592 49938736 50004352
kathleen hambrick's profile image
kathleen hambrick
The where command does not have parameters to use on others. To be more clear I am attempting to say which account a given record is locked. We have a mirrrored system and need to know if a given record is locked on the production or test account. The only difference between the two is the data pathname.... How can i tell if a lock is on live or test without having to be on that specific account? I merge the two lists together and use as a tool...It looks like this... (only with the columns lined up!) How can I take the PID or TTY and know what account that user is logged into - alternatively If there is a way for the data lock to tell me the full path to the data it has locked that would work also...

User Port Account PID Locks
kmh 14 TEST 10571 KBP TR80.HRA 02:31:13
jlk 37 LIVE 24461 ELG-RATE-MBR 541340843 00:13:43
tks 53 LIVE 20561 ELG-EXCLUSION 540740832*0 00:11:53
eas 55 LIVE 23526 CLM-MEMBER 218498958*1 00:08:03
eas 55 LIVE 23526 CLM-DETAIL BHV699 00:08:03
Brian Paige's profile image
Brian Paige
In UniVerse, I use the LIST.READU command in UV (or the smat -r command at Unix), and then use the inode in the listing to determine the file with various unix commands.  I don't know the command to list the locks in UniData.

Once you have the inode number, I think there's a -inum option on the find command in Linux, but I'm not sure how long that would take to run depending on the size of the directory path(s) you would be searching.
kathleen hambrick's profile image
kathleen hambrick
I can get the inode but don't see how to find the inode number for a given file. I already know the name of the file, just not the extended path name... How can I get the inode of a given file? That may help, it may not ;)
Thanks
Brian Paige's profile image
Brian Paige

Try something like this (you may have to adjust syntax for Linux - I'm more familiar with AIX):

                 find /uvdata/accountname -depth -inum 123456789

and it should return the full path to the file with that inode number.

Jon Kristofferson's profile image
Jon Kristofferson
Kathleen,

I don't believe there is a specific command for that. I use UniVerse, but I think this should work. You can change the data displayed.

CALL !GET.USERS(UV.USERS,MAX.USERS,SYS.USERS,USER.INFO,CODE)
NBR.LINES = DCOUNT(USER.INFO,@AM)
FOR I = 1 TO NBR.LINES
  USERID = USER.INFO<I,1>
  LOGNAME = USER.INFO<I,2>
  PID = USER.INFO<I,3>
  USERTYPE = USER.INFO<I,4>
  IF USERID <1 THEN
    CONTINUE
  END
  FS = USERINFO(1,PID,RETDAT)
  BEGIN CASE
    CASE FS EQ 0
      PRINT "INVALID USER: ":FMT(PID,"R%10"):" ":RETDAT<1,7>
    CASE FS EQ 1
      PRINT PID, RETDAT<1,1>, RETDAT<1,2>, RETDAT<1,7>, RETDAT<1,8>
              CASE @TRUE
       PRINT "INVALID CODE USED IN USERINFO FUNCTION!"
   END CASE
NEXT I
STOP
​
Kathleene Hunter's profile image
Kathleene Hunter

From the TCL Command prompt enter

WHO
WHAT
WHERE

This should have the information you are looking for.

Kathleené M Hunter
Resolution Provider LLC

Sam Powell's profile image
PARTNER Sam Powell
Hi Kathleen:

I use Universe version 11.3.1  Which has a command called LISTUSER and it shows the user#, PID, UserName, Type, Account and LogonTime.  

I created a UVBasic program that extends that command by allowing me to view specific information of the LISTUSER command.  I call it SHOWUSER.

This program allows me to type

SHOWUSER SAM  and it will show me any lines in the LISTUSER which contains the word SAM and ignores the rest.

Normally LISTUSER shows something like this.

UsrNo Pid...... UID.. UserName Type Acct.............. LogonTime...............
1 17532 1026 c.bustamante Term /u1/ASSOCIATE/IMPORT Thu Oct 7 01:09:46
2 21929 1027 c.rodriguez Term /u1/QSBROKERS/IMPORT Thu Oct 7 04:53:18
3 16666 1081 m.chung Term /u1/QSBROKERS/IMPORT Thu Oct 7 09:35:43 202
4 24957 1011 a.franco Term /u1/KKINTL/IMPORT Thu Oct 7 04:57:24 2021
5 11478 1030 d.gore Term /u1/WILSHIP/AGENCY Thu Oct 7 05:22:26 2021
6 14093 1002 cyndi Term /u1/ATSIMP Thu Oct 7 05:25:59 2021
7 17539 1062 j.freitas Term /u1/MDCB/IMPORT Thu Oct 7 06:11:26 2021
8 24781 1126 v.montoya Term /u1/KKINTL/IMPORT Thu Oct 7 05:40:17 2021
9 27346 1225 a.johnson Term /u1/WILSHIP/AGENCY Thu Oct 7 05:43:31 2021
10 19341 1074 k.schumacher Term /u1/PREMIER/IMPORT Thu Oct 7 06:13:33 2
11 22756 1031 d.hernandez Term /u1/CALLU/IMPORT Thu Oct 7 08:23:02 20
12 26141 1116 t.kim Term /u1/TASKCHB/IB Thu Oct 7 06:22:18 2021
13 31849 1050 g.robles Term /u1/KKINTL/IMPORT Thu Oct 7 06:29:03 2021
14 7014 1121 t.rodriguez Term /u1/QSBROKERS/IMPORT Thu Oct 7 06:38:38
15 15032 1025 c.blackstone Term /u1/MDCB/IMPORT Thu Oct 7 06:48:57 2
16 4951 1209 j.zavala Term /u1/MENDEZ/IMPORT Thu Oct 7 07:59:53 2021
17 2161 1028 c.smith Term /u1/QSBROKERS/IMPORT Thu Oct 7 09:17:13 202
18 15471 1200 d.szetho Term /u1/TEAMHAND/IMPORT Thu Oct 7 08:53:27 2021
19 31343 1064 j.martinez Term /u1/ATLASINT/IMPORT Thu Oct 7 07:09:35 20
20 27891 1134 a.montano Term /u1/CAPIN/IMPORT Thu Oct 7 09:50:15 2021
-21 24892 1168 mqm Phan /u1/ATSABI Mon Aug 30 12:32:23 2021

Neither does it do any pagination. 

But with the program below I can do this, plus it will do pagination.

:SHOWUSER SAM

UsrNo Pid...... UID.. UserName Type Acct.............. LogonTime...............
67 5368 1000 sam Term /u1/ATSSRC Thu Oct 7 08:00:29 2021
81 24954 1132 y.samper Term /u1/QSBROKERS/IMPORT Thu Oct 7 08:25:49 202
:

Hope it helps.
Sam


SEARCH = OCONV(FIELD(TRIM(@SENTENCE)," ",2,99),"MCU")
SENT = "LISTUSER"
PRINT @(0,0):@(-3):
EXECUTE SENT CAPTURING MSG
HEADER = MSG<1>
LCNT=0
IF SEARCH GT '' THEN
MAX.LINES=DCOUNT(MSG,@FM)
FOR LN = 1 TO MAX.LINES
TLINE = MSG<LN>
LINE = OCONV(MSG<LN>,"MCU")
IF INDEX(LINE,SEARCH,1) GE 1 THEN
IF LCNT=0 THEN
PRINT HEADER[1,80]
END
PRINT TLINE[1,80]
LCNT += 1
END
IF LCNT GE 22 THEN
PRINT "Press RETURN to continue":; INPUT Q
IF OCONV(Q,"MCU") = "Q" THEN STOP
LCNT=0
PRINT @(0,0):@(-3):
END
NEXT LN
END ELSE
MAX.LINES=DCOUNT(MSG,@FM)
LCNT=0
FOR LN = 1 TO MAX.LINES
LINE = MSG<LN>
PRINT LINE[1,80]
LCNT += 1
IF LCNT GE 22 THEN
PRINT "Press RETURN to continue":; INPUT Q
IF OCONV(Q,"MCU") = "Q" THEN STOP
PRINT @(0,0):@(-3)HEADER[1,80]
LCNT=0
END
NEXT LN
END
STOP
END
Mike Rajkowski's profile image
ROCKETEER Mike Rajkowski
Kathleen,

You could always use Python.

You will need to import the psutil module.

The following is a manual example.

1. First get the pid:
:listuser

Licensed(UDT+CP)/Effective Udt Sql iPhtm Pooled Total

( 32 + 32 ) / 64 3 0 0 0 3

UDTNO USRNBR UID USRNAME USRTYPE TTY IP-ADDRESS TIME DATE
1 29688 305727 mrajkowsk udt pts/1 Console 13:36:54 Oct 07 2021
2 21252 305727 mrajkowsk udt pts/2 udcs 12:37:45 Oct 07 2021
3 9780 305727 mrajkowsk udt pts/3 Console 13:58:40 Oct 07 2021

2. Go into Python
:python
python> import psutil
python> a = psutil.Process(9780)
python> a.cwd()
'C:\\U2\\ud82\\xdemo'
'C:\\U2\\ud82\\XDEMO'

3. you can also use it to see path to the files opened

python> import pprint
python> pprint.pprint(a.open_files())
[popenfile(path='C:\\U2\\ud82\\XDEMO\\VOC', fd=-1),
popenfile(path='C:\\U2\\ud82\\sys\\AE_DOC', fd=-1),
popenfile(path='C:\\U2\\ud82\\XDEMO\\MEMBERS', fd=-1),
popenfile(path='C:\\U2\\ud82\\XDEMO\\AE_COMS', fd=-1),
popenfile(path='C:\\U2\\ud82\\audit\\u2audlog1\\dat001', fd=-1),
popenfile(path='C:\\U2\\ud82\\sys\\ENGLISH.MSG', fd=-1),
popenfile(path='C:\\U2\\ud82\\audit\\u2audlog1\\over001', fd=-1),
popenfile(path='C:\\U2\\ud82\\bin\\udt.errlog', fd=-1)]


Once you get the hang of the psutil module, you could write your own module and function to integrate with your MultiValue solution.
Nik Kesic's profile image
Nik Kesic
Hi,

What you can do is develop a script around the following commands:

Using listuser from shell shows you the users logged in.

You can parse each logged in users name and pid:

[root@precom3vudt01 / ] #listuser

Licensed(UDT+CP)/Effective      Udt     Sql     iPhtm   Pooled          Total

    (  70 + 0   ) / 70          2       0       0       0               2

UDTNO USRNBR     UID  USRNAME USRTYPE              TTY         TIME        DATE
    1 4654492   44796  nxkesic     udt            pts/2     10:04:01 Oct 07 2021
    2 3278460     174      ads     udt            pts/0     12:08:46 Oct 08 2021​

Then use the following command to extract the user info of ads:

[root@precom3vudt01 / ] #sms -L 3278460|grep "Working directory:"|awk '{print $3}'|sed 's:^.\(.*\).$:\1:'
/ud/KEY
​

I hope this helps