home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / srvinfo.zip / srvinfo.cmd < prev   
OS/2 REXX Batch file  |  1997-01-11  |  18KB  |  453 lines

  1. /**********************************************************************/
  2. /* OBJECTIVE: Query remaining space on servers of a given domain      */
  3. /* Date: 22 Aug 1996                                                  */
  4. /* Revision: 8 Jan 1997 : Error handling enhanced. With no parameters,*/ 
  5. /*                        default domain is current  domain.          */
  6. /*           28 Aug 1996: handles nonformatted drives properly        */ 
  7. /*           8 Oct 1996: bug fix                                      */ 
  8. /*           12 Nov 1996: introduced color                            */ 
  9. /*           13 Nov 1996 : new command line arguments                 */      
  10. /*           14 Nov 1996 : handles CD-ROM                             */        
  11. /*           19 Nov 1996 : performs check on libraries                */
  12. /* Version: 1.09                                                      */
  13. /* Author:Daniel Szmulewicz                                           */
  14. /**********************************************************************/
  15.  
  16. Signal on halt
  17.  
  18.         /****************Load library files***********************/
  19.  
  20. If RxFuncQuery('SYSLOADFUNCS') \= 0 Then
  21.   Do
  22.     rc = RxFuncAdd('SYSLOADFUNCS', 'REXXUTIL', 'SYSLOADFUNCS')
  23.     If rc <> 0  then
  24.       Do
  25.         say 'Cannot register library REXXUTIL... Exiting...'
  26.         say 'Please make sure the file REXXUTIL.DLL is in your libpath.'
  27.         exit
  28.       End
  29.     Else
  30.       Call SYSLOADFUNCS
  31.   End
  32.  
  33. if Rxfuncquery('RxLoadFuncs') \= 0 then
  34.   Do
  35.  rc =  RxFuncAdd('RxLoadFuncs', 'RXUTILS', 'RXLOADFUNCS')
  36.     If rc <> 0  then
  37.       Do
  38.         say 'Cannot register library RXUTILS.. Exiting...'
  39.         say 'Please make sure the file RXUTILS.DLL is in your libpath.'
  40.         exit
  41.       End
  42.     Else
  43.      call RxLoadFuncs('QUIET')
  44. End
  45.  
  46.     rc = RxFuncAdd('LOADLSRXUTFUNCS', 'LSRXUT', 'LOADLSRXUTFUNCS')
  47.     If rc <> 0  then
  48.       Do
  49.         say 'Cannot register library LSRXUT... Exiting...'
  50.         say 'Please make sure the file LSRXUTIL.DLL is in your libpath.'
  51.         exit
  52.       End
  53.     Else
  54.       Call LOADLSRXUTFUNCS
  55.  
  56.         /**************Empty queue ****************************************/    
  57.  
  58. '@rxqueue /clear'
  59.  
  60.         /***************Initialize color***********************/
  61. '@ansi on 1>nul 2>&1'
  62. redonblue = '1B'x || '[37;44m'
  63. othergreen = '1B'x || '[46;43m'
  64. whiteongreen = '1B'x || '[37;46m'
  65. normal = '1B'x || '[0m'
  66. bright = '1B'x || '[1m'
  67.  
  68.         /********* Intro ********************/
  69.  
  70. arg domain server drive
  71.  
  72. domain = strip(domain)
  73. server = strip(server)
  74. drive = strip(drive)
  75. SELECT
  76.         WHEN domain = '' then
  77.            do
  78.                 say 'Please enter domain name, or press ENTER to query current domain.'
  79.                 say 'For help, type SrvInfo /help at the command prompt.'    
  80.                 pull domain .
  81.            end        
  82.         WHEN pos('?', domain) > 0 | pos('H', domain) > 0 | pos('/', domain) > 0 then
  83.                 call usage
  84.         WHEN domain <> '' & server <> '' & drive <> '' then
  85.             do
  86.                 Serverlist.number = server
  87.                 NETSERVERDISK = 150
  88.                 Srvname = '\\'||Serverlist.number
  89.                 myRc = NetEnumerate(NETSERVERDISK, 'srvDiskInfo', Srvname)
  90.             
  91.                 If myRc <> '0' then do
  92.                     say 'Could not find server' server 'on domain' domain'.'
  93.                     say  'Error ' myRc'.' 
  94.                     call DropLsRxutFuncs
  95.                     exit 9
  96.                 end
  97.  
  98.                 If srvDiskInfo.0 = 0 then do
  99.                   say 'No server disk drives'
  100.                   call DropLsRxutFuncs
  101.                   exit 0
  102.                  end
  103.  
  104.                 if length(drive) > 2 then call usage
  105.                 if length(drive) = 2 & substr(drive, 2,1) <> ':' then call usage 
  106.                 if length(drive) = 2 & substr(drive, 2,1) = ':' then drive = left(drive,1)
  107.                 Srvname = '\\'||server
  108.                 parse value Sysdrivemap(,'free') with freedrive .
  109.                 '@net use 'freedrive Srvname'\'drive||'$ 2>&1 | rxqueue'
  110.                 parse pull NetError ':' .
  111.                 if left(NetError, 3) = 'NET' then
  112.                     do
  113.                         call lineout, ''
  114.                         call lineout, 'Drive'||bright drive ||normal 'is a back-up tape, is non-formatted, or doesn''t exist...' 
  115.                         '@ECHO Y 2>&1 | net use 'freedrive '/d 1>NUL 2>NUL'
  116.                         exit
  117.                     end
  118.                 '@rxqueue /clear'           
  119.                 parse value SysDriveInfo(freedrive) with . freespace totalspace driveid
  120.                 say 
  121.                 if freespace == 0 then
  122.                     do
  123.                         call lineout, 'Drive'||bright drive||normal 'is a CD-ROM.' 
  124.                        '@ECHO Y 2>&1 | net use 'freedrive '/d 1>NUL 2>NUL'    
  125.                         exit
  126.                     end
  127.                 if freespace <> '' then 
  128.                     call lineout, 'Drive'||bright drive||normal 'has in total'|| bright Right(Format(totalspace/1048576,,0),5) normal|| 'MB, of which' bright Right(Format(freespace/1048576,,0),4) normal || 'MB is free.'
  129.                 else call lineout, 'Drive 't 'is not a valid drive.'
  130.                '@ECHO Y 2>&1 | net use 'freedrive '/d 1>NUL 2>NUL'
  131.                 exit    
  132.             end
  133.         WHEN domain <> '' & server <> '' then
  134.             do
  135.                 Serverlist.number = server
  136.                 NETSERVERDISK = 150
  137.                 Srvname = '\\'||Serverlist.number
  138.                 myRc = NetEnumerate(NETSERVERDISK, 'srvDiskInfo', Srvname)
  139.             
  140.                 If myRc <> '0' then do
  141.                     say 'Could not find server' server 'on domain' domain'. Error 'myRc'.' 
  142.                     call DropLsRxutFuncs
  143.                     exit 9
  144.                 end
  145.  
  146.                 If srvDiskInfo.0 = 0 then do
  147.                   say 'No server disk drives'
  148.                   call DropLsRxutFuncs
  149.                   exit 0
  150.                  end
  151.  
  152.                 call WhereOutput
  153.                 call shebang
  154.                 if output <> 'CON:' then
  155.                 call lineout, ''
  156.                 exit
  157.             end    
  158.         OTHERWISE nop
  159. END
  160.  
  161.         /********Get number and names of servers in the domain specified**************/
  162.  
  163. GetServers:
  164. NETSERVER = 160
  165. SrvType = -1
  166. if domain = '' then
  167.      do
  168.         Parse value Rxuserinfo() with . . domain
  169.         if domain = '' then do
  170.              say 'Can''t query domain. Try manually.'
  171.              exit 
  172.            end 
  173.         myrc = NetEnumerate(NETSERVER, 'serverlist')    /*Get domain controller name*/
  174.         if myrc <> 0 then
  175.               do
  176.                         say 'Error. Domain:' domain||':' myrc
  177.                         say 'Exiting...'
  178.                         exit
  179.               end
  180.         SrvName = '\\'||Serverlist.1
  181.      end
  182. else
  183.      do
  184.         Srvname = RxDCName(domain)        /*Get domain controller name of other domain*/
  185.         if pos('ERROR', Srvname) > 0 then do
  186.                 say 'Please make sure the domain you entered is valid:' domain 
  187.                 say 'Will exit for now...'
  188.                 exit
  189.             end
  190.      end
  191.  
  192. myrc = NetEnumerate(NETSERVER, 'serverlist', SrvName, SrvType, domain) /*Enumerate servers on domain*/
  193. if myrc <> 0 then
  194.       do
  195.         say 'Error:' myrc
  196.         say 'Exiting...'
  197.         exit
  198.       end
  199. say Serverlist.0 'server(s) were found on specified domain' '('domain').'
  200. say
  201. do i=1 to ServerList.0
  202.         say '       'bright||i||normal||',' Serverlist.i
  203. end
  204.  
  205.  
  206.        /**********Get number of disks and drive letters on servers found************/
  207. DO FOREVER
  208.         say
  209.         say 'Please enter the number of the server you want to query,'
  210.         say 'or type "'bright'a'normal'" for all, "'bright'c'normal'" for cancel.'
  211.         number = Sysgetkey(NOECHO)
  212.         number = translate(number)
  213.         SELECT
  214.                 WHEN Datatype(number) = 'NUM' & number <= Serverlist.0 then
  215.                      do
  216.                         call WhereOutput
  217.                         call shebang
  218.                         leave
  219.                      end
  220.                 WHEN Datatype(number) = 'CHAR' & number = 'A' then
  221.                      do
  222.                         call WhereOutput
  223.                         totalspacedomain = 0
  224.                         totalfreespacedomain = 0
  225.                         do number = 1 to Serverlist.0
  226.                         call shebang
  227.                         totalspacedomain = totalspacedomain + totalspace
  228.                         totalfreespacedomain = totalfreespacedomain + freespace
  229.                          end
  230.                          if output = 'CON:' then 
  231.                                 do
  232.                          call lineout output, bright||'Total'||normal' occupied space on domain'||bright domain ||normal' is'bright Right(Format(totalspacedomain/1048576,,0),8)||normal 'MB.'
  233.                          call lineout output, bright||'Total'||normal' free space on domain'||bright domain ||normal' is    'bright||othergreen Right(Format(totalfreespacedomain/1048576,,0),8)||normal 'MB.'
  234.                                 end    
  235.                          else   
  236.                                 do
  237.                          call lineout output, 'Total occupied space on domain' domain 'is' Right(Format(totalspacedomain/1048576,,0),8) 'MB.'
  238.                          call lineout output, 'Total free space on domain' domain 'is    ' Right(Format(totalfreespacedomain/1048576,,0),8) 'MB.'
  239.                                 end    
  240.                          leave
  241.                       end
  242.                 WHEN Datatype(number) = 'CHAR' & number ='C' then
  243.                       exit
  244.                 OTHERWISE
  245.                    do
  246.                         say 'You did not type valid input.'
  247.                         say 'Come again...'
  248.                         flag = 1
  249.                         ITERATE
  250.                   end
  251.         END
  252. END
  253.  
  254. rc =lineout(output)
  255. if output <> 'CON:' then
  256.     call lineout, ''
  257. call DropLsRxutFuncs
  258. call RxFuncDrop 'LoadLsRxutFuncs'
  259. '@rxqueue /clear'
  260. exit
  261.  
  262. shebang:
  263. NETSERVERDISK = 150
  264. Srvname = '\\'||Serverlist.number
  265. myRc = NetEnumerate(NETSERVERDISK, 'srvDiskInfo', Srvname)
  266.  
  267. If myRc <> '0' then do
  268.   say 'Got error from NetEnumerate() ' myRc
  269.   call DropLsRxutFuncs
  270.   exit 9
  271.  end
  272.  
  273. If srvDiskInfo.0 = 0 then do
  274.   say 'No server disk drives'
  275.   call DropLsRxutFuncs
  276.   exit 0
  277.  end
  278.  
  279. call lineout output, ''
  280. if output = 'CON:' then
  281.     call lineout output, '        Server' bright||Serverlist.number||normal 'has' bright||(srvDiskInfo.0 - 2)||normal 'disk drives:'
  282. else
  283.     call lineout output, '        Server' Serverlist.number 'has' (srvDiskInfo.0 - 2) 'disk drives:'
  284. call lineout output, ''
  285.  
  286.  do i=1 to srvDiskInfo.0
  287.         /*say srvDiskInfo.i*/
  288.         srvdiskletter.i = left(SrvDiskinfo.i, 1)
  289.  end
  290.  
  291.         /************Calculate Free Space*************/
  292. /*trace '?i'*/
  293. parse value Sysdrivemap(,'free') with freedrive .
  294. do i=3 to SrvDiskInfo.0
  295.         '@rxqueue /clear'
  296.         '@net use 'freedrive Srvname'\'SrvDiskletter.i||'$ 2>&1 | rxqueue'
  297.         parse pull NetError ':' .
  298.         if left(NetError, 3) = 'NET' then
  299.           do
  300.             if output = 'CON:' then
  301.             call lineout output, 'Drive'||bright SrvDiskletter.i||normal 'is unknown (back-up tape, non-formatted HD...).' 
  302.             else
  303.                 do
  304.                     call lineout output, 'Drive' SrvDiskletter.i 'is unknown( back-up tape, non-formatted...).'
  305.                     call Statuscursor
  306.                 end    
  307.             totalspace.i = 0
  308.             freespace.i = 0 
  309.             ITERATE i
  310.           end
  311.         parse value SysDriveInfo(freedrive) with . freespace.i totalspace.i driveid
  312.         if freespace.i == 0 then
  313.             do
  314.                 totalspace.i = 0    
  315.                 if output = 'CON:' then do
  316.                     call lineout output, 'Drive'||bright SrvDiskletter.i||normal 'is a CD-ROM.' 
  317.                    '@ECHO Y 2>&1 | net use 'freedrive '/d 1>NUL 2>NUL'
  318.                     end
  319.                     else
  320.                         do
  321.                             call lineout output, 'Drive' SrvDiskletter.i 'is a CD-ROM.'
  322.                             '@ECHO Y 2>&1 | net use 'freedrive '/d 1>NUL 2>NUL'      
  323.                             call Statuscursor
  324.                         end    
  325.                 iterate i                    
  326.             end
  327.         if output   = 'CON:' then
  328.         call lineout output, 'Drive'||bright SrvDiskletter.i||normal 'has in total'|| bright Right(Format(totalspace.i/1048576,,0),5) normal|| 'MB, of which' bright Right(Format(freespace.i/1048576,,0),4) normal || 'MB is free.'
  329.         else
  330.             do
  331.                 call lineout output, 'Drive' SrvDiskletter.i 'has in total' Right(Format(totalspace.i/1048576,,0),5) 'MB, of which' Right(Format(freespace.i/1048576,,0),4) 'MB is free.'
  332.                 call StatusCursor
  333.             end
  334.         '@ECHO Y 2>&1 | net use 'freedrive '/d 1>NUL 2>NUL'
  335. end
  336. freespace = 0
  337. totalspace = 0
  338.  
  339. do i=3 to SrvDiskInfo.0
  340.         totalspace = totalspace + totalspace.i
  341.         freespace = freespace + freespace.i
  342. end
  343. call lineout output, ''
  344. if output   = 'CON:' then
  345.     do
  346. call lineout output, '    Total absolute space is' bright Right(Format(totalspace/1048576,,0),6)|| normal 'MB.'
  347. call lineout output, '    Total free space is    ' bright || whiteongreen Right(Format(freespace/1048576,,0),6)||normal 'MB.' 
  348.     end
  349. else
  350.     do
  351. call lineout output, '    Total absolute space is' Right(Format(totalspace/1048576,,0),6) 'MB.'
  352. call lineout output, '    Total free space is    ' Right(Format(freespace/1048576,,0),6) 'MB.'
  353.     end
  354. call lineout output, ''
  355. call lineout output, Copies('*',59)
  356. return
  357.  
  358.         /***************** Unload library files ***********************/
  359.  
  360. WhereOutput:
  361. DO FOREVER
  362. say 'Where do you want the output to be displayed?'
  363. say '('bright'F'normal')ile, default ('bright'P'normal')rinter, or just press 'bright'ENTER'normal' for screen output'
  364. output = Sysgetkey(NOECHO)
  365. output = translate(output)
  366. SELECT
  367.         WHEN output = 'F' then
  368.           do
  369.                 output = 'srvinfo.logfile'
  370.                 rc = Sysfiledelete(output)
  371.                 say
  372.                 call charout, ' Writing '||bright'"srvinfo.logfile"'||normal' in current directory...'
  373.                 parse value syscurpos() with row col              
  374.                 call lineout output, Copies('*',59)
  375.                 call lineout output, 'Logfile by SrvInfo'
  376.                 call lineout output, Copies('*',59)
  377.                 return
  378.           end
  379.         WHEN output = 'P' then
  380.           do
  381.                 output = 'PRN:'
  382.                 say
  383.                 call charout, '  'bright'Sending output to LPT1'||normal||'...'
  384.                 parse value syscurpos() with row col              
  385.                 call lineout output, Copies('*',59)
  386.                 call lineout output, 'Print-out from SrvInfo'
  387.                 call lineout output, Copies('*',59)
  388.                 return
  389.           end
  390.         WHEN output = '0D'x then
  391.           do
  392.                 output = 'CON:'
  393.                 call SysCls
  394.                 return
  395.           end
  396.         OTHERWISE
  397.           do
  398.                 Say 'You did not enter valid input.'
  399.                 Say 'Try again...'
  400.                ITERATE
  401.           end
  402. END
  403. END
  404.  
  405.                 /***************************/
  406. Statuscursor:                                     
  407. /*trace 'i'*/                                     
  408. if h = 'H' then
  409.     h = col - 1
  410. else nop
  411. h = h + 1
  412. pos = syscurpos(row, h)
  413. call charout, '.' 
  414. return                                            
  415.  
  416.             /*********************************/
  417. usage:
  418.                 say
  419.                 say '  'bright'SrvInfo.cmd version 1.07'normal
  420.                 say
  421.                 say  
  422.                 say '      Purpose: Queries free space on server drives.' 
  423.                 say
  424.                 say '      Usage:'
  425.                 say
  426.                 say '                'redonblue||bright'SrvInfo [Domain] [Server] [Drive]'normal
  427.                 say 
  428.                 say          
  429.                 say '                 Examples:'
  430.                 say '                                SrvInfo'               
  431.                 say '                       or:'
  432.                 say '                                SrvInfo M024D001'   
  433.                 say '                       or:'        
  434.                 say '                                SrvInfo M024D001 M024S001'
  435.                 say '                       or:'                
  436.                 say '                                SrvInfo M024D001 M024S001 E:'
  437.                 say 
  438.                 say '   Note: If you don''t specify any option, SrvInfo'
  439.                 say '           will assist you in the parameter specification.'
  440.                 say 
  441.                 say 'Enjoy!'
  442.                 exit
  443.  
  444.             /*****************************/
  445.  
  446. Halt:
  447. '@ECHO Y 2>&1 | net use 'freedrive '/d 1>NUL 2>NUL'
  448. '@rxqueue /clear'
  449. say
  450. say 'Program interrupted by user, exiting...'
  451. exit
  452.  
  453.