home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netdor3.zip / DISK_12 / IMAGE11.ZIP / ADMTOOLS / MULTCMD.CMD < prev    next >
OS/2 REXX Batch file  |  1993-08-20  |  6KB  |  144 lines

  1. /*****************************************************************************
  2.  *              MULTCMD - Execute a Command on Multiple Servers              *
  3.  *                       T. Bridgman (CORE at WATSON)                        *
  4.  *****************************************************************************
  5.  *                    Licensed Materials-Property of IBM                     *
  6.  *               5604-472 (c) Copyright IBM Corporation, 1993                *
  7.  *                           All rights reserved.                            *
  8.  *                  US Government Users Restricted Rights -                  *
  9.  *                 Use, duplication or disclosure restricted                 *
  10.  *                by GSA ADP Schedule Contract with IBM Corp.                *
  11.  *****************************************************************************
  12.  * Change History                                                            *
  13.  * version 1.0 - 10 Oct 90                                                   *
  14.  * version 1.1 - 8 Sep 91                                                    *
  15.  * - Support command line or function call                                   *
  16.  * - Support any server, not just domain controllers                         *
  17.  * - Allow server names to optionally be preceeded by '\\'                   *
  18.  * - Add /S option to silence the commentary.                                *
  19.  * 30 Oct 91 - teb                                                           *
  20.  * - Add support to pass strings of multiple commands to servers.            *
  21.  *****************************************************************************/
  22. trace 'O'
  23. '@ECHO OFF'
  24. parse source . How .
  25. CmdMode = (How = 'COMMAND')
  26. if CmdMode
  27.   then parse arg Command ',' MachList
  28.   else parse arg Command, MachList
  29. parse upper var MachList MachList '/' SlashParms
  30. /**** PTR 93 start ****/
  31. if SlashParms <> ''
  32.   then SlashParms = translate('/'SlashParms)
  33. /**** PTR 93 end ****/
  34. if abbrev(Command, '?') | Command = '' | MachList = ''
  35.   then signal Tell
  36.  
  37. call LoadRxUtils
  38.  
  39. if rxos2ver() < 1.2
  40.   then call Error 'MULTCMD requires OS/2 1.2 or later.'
  41.  
  42. Command = ProcessCmd(Command)
  43.  
  44. /**** PTR 93 start ****/
  45. Quiet = wordpos('/S', SlashParms) 
  46. if Quiet > 0
  47.   then SlashParms = strip(space(delword(SlashParms, Quiet, 1)))
  48. Quiet = (Quiet > 0)
  49. if SlashParms <> ''
  50.   then do
  51.     say 'Error: Invalid parameters specified:' SlashParms
  52.     exit 2
  53.   end
  54. /**** PTR 93 end ****/
  55. call Msg
  56. call Msg 'Performing "'Command'"...'
  57. do until MachList = ''
  58.   parse var MachList Machine MachList
  59.   if left(Machine, 2) <> '\\'
  60.     then Machine = '\\'Machine
  61.   call Msg '...on' Machine':'
  62.   'NET.EXE ADMIN' Machine' /C' Command
  63.   if rc <> 0
  64.     then call Msg 'rc('rc')'
  65.   call Msg
  66. end
  67. if CmdMode
  68.   then exit 0
  69.   else return 0
  70.  
  71. Msg:
  72. if \Quiet
  73.   then say arg(1)
  74. return
  75.  
  76. /*****************************************************************************
  77.  * PROCESSCMD                                                                *
  78.  *****************************************************************************/
  79. ProcessCmd: procedure
  80. parse arg Cmd
  81. P0 = pos('&', Cmd)
  82. do while P0 <> 0
  83.   if substr(Cmd, P0-1, 1) <> '^'
  84.     then do
  85.       Cmd = left(Cmd, P0-1)'^'substr(Cmd, P0)
  86.       P0 = P0+1
  87.     end
  88.   P0 = pos('&', Cmd, P0+1)
  89. end
  90. if left(Cmd, 1) <> '(' then Cmd = '('Cmd
  91. if right(Cmd, 1) <> ')' then Cmd = Cmd')'
  92. return Cmd
  93.  
  94. /*****************************************************************************
  95.  * ERROR                                                                     *
  96.  *****************************************************************************/
  97. Error:
  98. parse arg EMsg
  99. say d2c(7)EMsg
  100. if CmdMode
  101.   then exit 2
  102.   else return 2
  103.  
  104. LoadRxUtils: procedure                                                   
  105. if \rxfuncadd('RXLOADFUNCS', 'RXUTILS', 'RXLOADFUNCS')                   
  106.   then do                                                                
  107.     signal on syntax name LoadRxUtils2                                   
  108.     call rxLoadFuncs 'QUIET'                                             
  109.   end                                                                    
  110. return 0                                                                 
  111.                                                                          
  112. LoadRxUtils2:                                                            
  113. signal off syntax    /* Turn off temp error trap */                      
  114. /* If you have an error trap in the program, use the following line inste
  115. signal on syntax name syntax                                             
  116. */                                                                       
  117. select                                                                   
  118.   when rc = 40                                                           
  119.     then call rxLoadFuncs                                                
  120.   when rc = 43                                                           
  121.     then do                                                              
  122.       say 'Error:  RXUTILS.DLL not found.'                               
  123.       exit 2                                                             
  124.     end                                                                  
  125.   otherwise do                                                           
  126.     say 'Error: Error' rc 'registering RXUTILS functions.'               
  127.     exit 2                                                               
  128.   end                                                                    
  129. end                                                                      
  130. return 0                                                                 
  131.  
  132. Tell:
  133. say
  134. say 'MULTCMD command, server [...] [/S]'
  135. say
  136. say 'Execute the specified command on multiple servers.'
  137. say 'MULTCMD can be called as a function or from the command line.'
  138. say
  139. say '  /S - don''t provide any commentary.'
  140. say
  141. say 'To pass strings of commands joined by the & or && operators,'
  142. say 'remember to insert a caret (^) before each & symbol: ^& or ^&^&'
  143. exit 0
  144.