home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / lasersta.zip / lsc.cmd < prev   
OS/2 REXX Batch file  |  2002-05-17  |  12KB  |  319 lines

  1. /*---------------------------------------------------------------------------*\
  2. |  Check Lan Server Status                    (C) Alain Rykaert - MAR96-NOV98 |
  3. \*---------------------------------------------------------------------------*/
  4.     Version = '2.34'
  5.     Say '* LSST Version' Version
  6.  
  7.     Parse Upper Arg ServerName Option
  8.  
  9.     If Option = '/STAT'                        /* check the statistics flag*/
  10.       Then Stat = 1
  11.       Else Stat = 0
  12.  
  13.     Call Init                                   /* load DLL's & other stuff*/
  14.  
  15.     If ServerName = ''
  16.       Then Do
  17.              Say '*'
  18.              Say '* LAN Server Check & Statistics'
  19.              Say '*'
  20.              Say '* Usage: LSC {*} {ServerName} {/STAT}'
  21.              Say '*'
  22.              Say '* Sample: LSC \\DC02 /STAT'
  23.              Say '*'
  24.              Exit X2D('1600')
  25.            End
  26.       Else Nop
  27.  
  28.     If ServerName = '*'
  29.       Then Do
  30.              RC = NetGetInfo(350, 'WkstaInfo','')
  31.              If RC = 0
  32.                Then ServerName = WkstaInfo.ComputerName
  33.                Else Call ChkError RC
  34.            End
  35.       Else ServerName = ServerName
  36.  
  37.     ServerName = Strip(ServerName,'L','\')
  38.  
  39.     Say '* Server Name:' '\\'ServerName
  40.  
  41.     RC = NetGetInfo(370, 'ServerModalInfo', '\\'ServerName)
  42.     If RC = 0
  43.       Then Do
  44.              LSRFile = '\\'ServerName'\ibmlan$\ibmlan.ini'
  45.              Say Left('*',50,'-')
  46.              Say '* Get Accounts:'
  47.              Say Left('*',50,'-')
  48.              ServerRole = ServerModalInfo.Role
  49.              DCName = ServerModalInfo.Primary
  50.  
  51.              Say '  Server Role:' ServerRole
  52.              If WordPos('Primary', ServerRole) > 0
  53.                Then PDC = 1                                 /* check if PDC*/
  54.                Else PDC = 0
  55.              If WordPos('Primary', ServerRole) > 0 |,
  56.                 WordPos('Backup', ServerRole)  > 0
  57.                Then DCCheck = 1               /* check if Domain Controller*/
  58.                Else DCCheck = 0
  59.              Say '  Domain controller for requester domain: \\'DCName
  60.  
  61.              Say Left('*',50,'-')
  62.              Say '* Get Users:'
  63.              Say Left('*',50,'-')
  64.              Call NetEnumerate 280, 'DCUsers', '\\'DCName
  65.              Say '  Number of users defined on \\'DCName ':' DCUsers.0
  66.              If PDC = 1
  67.                Then Nop
  68.                Else Do
  69.                       Call NetEnumerate 280, 'Users', '\\'ServerName
  70.                       Say '  Number of users replicated to \\'ServerName ':' Users.0
  71.                     End
  72.            End
  73.       Else Call ChkError RC
  74.  
  75.     Say Left('*',50,'-')
  76.     Say '* Get services:'
  77.     Say Left('*',50,'-')
  78.     Call NetEnumerate 170, 'ServiceInfo', '\\'ServerName
  79.     ServiceInfo = ''
  80.     If ServiceInfo.0 > 5                   /* if more than 5 split the line*/
  81.       Then Do
  82.              Do i = 1 to 5
  83.                ServiceInfo = ServiceInfo ServiceInfo.i
  84.              End
  85.              ServiceInfo = ServiceInfo '0A0D20'x
  86.              Do i = 6 to ServiceInfo.0
  87.                ServiceInfo = ServiceInfo ServiceInfo.i
  88.              End
  89.            End
  90.       Else Do
  91.              Do i = 1 to ServiceInfo.0
  92.                ServiceInfo = ServiceInfo ServiceInfo.i
  93.              End
  94.            End
  95.     Say ' ' || ServiceInfo
  96.  
  97.     If DCCheck = 1                              /* either Primary or Backup*/
  98.       Then Do
  99.               Say Left('*',50,'-')
  100.               Say '* Check DCDB Replicator:'
  101.               Say Left('*',50,'-')
  102.               If WordPos('DCDBREPL', ServiceInfo) > 0
  103.                 Then Say '  DCDB replicator running'
  104.                 Else Do
  105.                         Call Beep 2000,50
  106.                         Say '  DCDB replicator NOT running' Left('<',25,'-')
  107.                      End
  108.               Say '  Checking DCDB tree:'
  109.               Dir.0 = 9
  110.               Dir.1 = 'apps'
  111.               Dir.2 = 'devices'
  112.               Dir.3 = 'data'
  113.               Dir.4 = 'files'
  114.               Dir.5 = 'images'
  115.               Dir.6 = 'lists'
  116.               Dir.7 = 'printers'
  117.               Dir.8 = 'scripts'
  118.               Dir.9 = 'users'
  119.  
  120.               Do i = 1 to Dir.0
  121.                 Call SysFileTree '\\'ServerName'\ibmlan$\dcdb\'Dir.i'\*.rp$', 'Stem', 'FO'
  122.                 If Stem.0 = 0
  123.                   Then Status = '-none-'
  124.                   Else Do
  125.                          x = LastPos('\', Stem.1) + 1
  126.                          Parse Value Substr(Stem.1, x) With Status '.' .
  127.                        End
  128.                 If Status = 'OK'
  129.                   Then Check = ' '
  130.                   Else Check = '*'
  131.                 Say ' ' i Left(Translate(Dir.i),9) Check,
  132.                           Left(Status,9) Stream(Stem.1, 'C', 'Query DateTime')
  133.               End
  134.               Call SysFileTree '\\'ServerName'\ibmlan$\dcdb\users\', 'Stem', 'DO'
  135.               Say '     └──>' Stem.0 'directories'
  136.               If PDC = 1
  137.                 Then Nop
  138.                 Else Do
  139.                        Call SysFileTree '\\'DCName'\ibmlan$\dcdb\users\', 'Stem', 'DO'
  140.                        Say '  Directories on \\'DCName '─>' Stem.0
  141.                      End
  142.            End
  143.       Else Nop
  144.  
  145.     If Stat = 1
  146.       Then Do
  147.              Say Left('*',50,'-')
  148.              Say '* Statistics:'
  149.              Say Left('*',50,'-')
  150.              Call NetGetInfo 160, 'ServerInfo', '\\'ServerName
  151.              Call NetGetInfo 195, 'StatisticsInfo', '\\'ServerName, 1, 0
  152.              Call NetEnumerate 60, 'FileInfo', '\\'ServerName
  153.              Call NetEnumerate 190, 'Shares', '\\'ServerName
  154.              Call NetEnumerate 180, 'Sessions', '\\'ServerName
  155.  
  156.              Say '  Statistics Time:' Strip(StatisticsInfo.Start,'T','0A'x)
  157.  
  158.              MaxConnections = ServerInfo.Connections
  159.              ActiveConnections = 0
  160.              Do i = 1 to Sessions.0
  161.                ActiveConnections = ActiveConnections + Sessions.i.Num_Conns
  162.              End
  163.  
  164.              Say '  Number of shares:' Shares.0'/'ServerInfo.Shares
  165.              SharesOnDemand = 0
  166.              Do i = 1 to Shares.0
  167.                If WordPos('ADMIN$', Shares.i)    > 0 |,
  168.                   WordPos('DCDBREPL$', Shares.i) > 0 |,
  169.                   WordPos('NETLOGON', Shares.i)  > 0 |,
  170.                   WordPos('IBMLAN$', Shares.i)   > 0 |,
  171.                   WordPos('IPC$', Shares.i)      > 0 |,
  172.                   WordPos('REPL$', Shares.i)     > 0 |,
  173.                   Length(Shares.i) = 2
  174.                   Then Nop
  175.                   Else SharesOnDemand = SharesOnDemand + 1
  176.              End
  177.              Say '  Shares on demand:' SharesOnDemand
  178.  
  179.              Say '  Total of used sessions:' StatisticsInfo.Sopens
  180.              Say '  Number of active sessions:' Sessions.0
  181.              Say '  Auto Disconnect Parameter:' ServerInfo.Disc
  182.              Say '  Auto Disconnects:' StatisticsInfo.Stimedout
  183.              Say '  Closed by Errors:' StatisticsInfo.Serrorout
  184.              Say '  Number of active connections:' ActiveConnections'/'ServerInfo.Connections
  185.              Say '  Password Violations:' StatisticsInfo.PwErrors
  186.              Say '  Permission Errors:' StatisticsInfo.PermErrors
  187.              Say '  System Errors:' StatisticsInfo.SysErrors
  188.              Say '  Number of total opened files:' StatisticsInfo.Fopens
  189.              Say '  Number of current open files:' FileInfo.Count'/'ServerInfo.OpenFiles
  190.              Say '  Total Bytes TX:' StatisticsInfo.BytesSent Trunc((Format(StatisticsInfo.BytesSent,,0,0) / 1000)) 'KB'
  191.              Say '  Total Bytes RX:' StatisticsInfo.BytesRcvd Trunc((Format(StatisticsInfo.BytesRcvd,,0,0) / 1000)) 'KB'
  192.              Say '  Total Bytes TX+RX:' Trunc((Format(StatisticsInfo.BytesSent,,0,0) + Format(StatisticsInfo.BytesRcvd,,0,0)) / 1000) 'KB'
  193.              Say '  Buffers Needed:' StatisticsInfo.ReqBufNeed
  194.              Say '  Large Buffers Needed:' StatisticsInfo.BigBufNeed
  195.              Say '  Total print jobs queued:' StatisticsInfo.Jobsqueued
  196.              Say '  Average response time:' StatisticsInfo.Avresponse
  197.  
  198.              Call GetNBStat ServerName                 /* get NetBIOS stats*/
  199.            End
  200.       Else Nop
  201.  
  202.     Exit X2D('FE00')
  203.  
  204.  INIT:/* --------------------------------------------------------------------*/
  205.  
  206.    '@echo off'
  207.     BootDrive = Left(Value('COMSPEC',,'OS2ENVIRONMENT'),2)
  208.  
  209.     If RxFuncQuery('SysLoadFuncs')
  210.       Then Do
  211.              Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  212.              Call SysLoadFuncs
  213.            End
  214.       Else Nop
  215.  
  216.     LSRDrive = ''                      /* Check for Lan Server Drive Letter*/
  217.     PPath = Value('PATH',,'OS2ENVIRONMENT')
  218.     x = Pos('IBMLAN\NETPROG', PPath) -3
  219.     If x > 0
  220.       Then LSRDrive = SubStr(PPath, x, 2)
  221.       Else Do
  222.              Say '! Could not determine the Lan Requester path' '07'x
  223.              Exit X2D('1604')
  224.            End
  225.  
  226.     If Stream(LSRDrive'\ibmlan\netlib\lsrxut.dll', 'C', 'Query Exists') <> ''
  227.       Then Do
  228.              If RxFuncQuery('LoadLSRXUTFuncs')
  229.                Then Do
  230.                       Call RxFuncAdd 'LoadLsRxutFuncs', 'LSRXUT', 'LoadLsRxutFuncs'
  231.                       Call LoadLsRxutFuncs
  232.                     End
  233.                Else Nop
  234.            End
  235.       Else Do
  236.              Say '! Could not find' LSRDrive'\IBMLAN\NETLIB\LSRXUT.DLL' '07'x
  237.              Exit X2D('0800')
  238.            End
  239.  
  240.     Return
  241.  
  242.  CHKERROR:/* ----------------------------------------------------------------*/
  243.  
  244.     Parse Arg RCode
  245.  
  246.     Say '! Error:' RCode '07'x
  247.     Exit X2D('1600')
  248.  
  249.     Return
  250.  
  251.  GETNBSTAT:/* ---------------------------------------------------------------*/
  252.  
  253.     Parse Arg ServerName
  254.  
  255.     LAA         = ''
  256.     UAA         = ''
  257.     FreeNCB     = ''
  258.     MaxNCB      = ''
  259.     PendingSess = ''
  260.     MaxSess     = ''
  261.     UsedNames   = ''
  262.     NumSess     = ''
  263.     NumNCB      = ''
  264.  
  265.     If Stream(BootDrive'\os2\nbjdstat.exe', 'C', 'Query Exists') <> ''
  266.       Then Nop
  267.       Else Do
  268.              Say '* Could not find' BootDrive'\OS2\NBJDSTAT.EXE' '07'x
  269.              Exit X2D('0800')
  270.            End
  271.  
  272.     TempFile = BootDrive'\os2\lsc.tmp'
  273.  
  274.    'nbjdstat' ServerName '/v >' TempFile
  275.     If RC = 0
  276.       Then Do
  277.              Do While Lines(TempFile)
  278.                LLine = LineIn(TempFile)
  279.                Select
  280.                  When Left(LLine,11) = 'MAC Address'
  281.                    Then LAA = Translate(Space(SubStr(LLine, 15),0))
  282.                  When Left(LLine,26) = 'Universal Adapter Address'
  283.                    Then UAA = SubStr(LLine, 27)
  284.                  When Left(LLine,19) = 'Number of Free NCBs'
  285.                    Then FreeNCB = SubStr(LLine, LastPos('.',LLine) +1)
  286.                  When Left(LLine,22) = 'Configured NCB maximum'
  287.                    Then MaxNCB = SubStr(LLine, LastPos('.',LLine) +1)
  288.                  When Left(LLine,26) = 'Number of pending sessions'
  289.                    Then PendingSess = SubStr(LLine, LastPos('.',LLine) +1)
  290.                  When Left(LLine,26) = 'Configured session maximum'
  291.                    Then MaxSess = SubStr(LLine, LastPos('.',LLine) +1)
  292.                  When Left(LLine,24) = 'Number of names in table'
  293.                    Then UsedNames = SubStr(LLine, LastPos('.',LLine) +1)
  294.                  Otherwise Nop
  295.                End
  296.                If PendingSess > 0 & MaxSess > 0
  297.                  Then Do
  298.                         NumSess = PendingSess || '/'MaxSess
  299.                         NumNCB = MaxNCB - FreeNCB || '/'MaxNCB
  300.                       End
  301.                  Else Nop
  302.              End
  303.              Say Left('*',50,'-')
  304.              Say '* NIC:'
  305.              Say Left('*',50,'-')
  306.              Say '  Local Adapter Address:' LAA
  307.              Say '  Universal Adapter Address:' UAA
  308.              Say '  Number of sessions:' NumSess
  309.              Say '  Number of NCBs:' NumNCB
  310.              Say '  Number of names:' UsedNames
  311.            End
  312.       Else Say '! Could not get NetBIOS statistics from' ServerName '07'x
  313.  
  314.     Call Stream TempFile, 'C', 'Close'               /* delete the tmp file*/
  315.     Call SysFileDelete(TempFile)
  316.  
  317.     Return
  318.  
  319.