home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / remcmd.zip / REMCMDC1.CMD < prev    next >
OS/2 REXX Batch file  |  1993-05-10  |  4KB  |  168 lines

  1. /* Rexx */
  2.  
  3. pq = 'REMCMD'
  4.  
  5. /* Register Rexx external functions */
  6. If RxFuncQuery('RXACSMGT') Then
  7.   Call RxFuncAdd 'RXACSMGT','YDBAACSM','YDBAACSM'
  8. If RxFuncQuery('APPC') Then
  9.   Call RxFuncAdd 'APPC','SAAAPPC','APPCSRV'
  10. If RxFuncQuery('SYSSLEEP') Then
  11.   Do
  12.   Call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  13.   Call SysLoadFuncs
  14.   End
  15. If RxFuncQuery('RxCreateRexxThread') Then
  16.   Do
  17.   Call RxFuncAdd 'RxYdbaUtilInit','YDBAUTIL','RxYdbaUtilInit'
  18.   Call RxYdbaUtilInit
  19.   End
  20.  
  21. Call Define_Callback_Tp
  22.  
  23. Call RxAcsMgt 'display_sna_global_info','sg.'
  24. loclu=sg.4;Drop sg.
  25.  
  26. /* Prompt user */
  27. Say;Say 'Enter LU-Alias of remote workstation:'
  28. Say '(Type * to end)'
  29. Parse Upper LineIn partlu
  30. If partlu = '*' Then
  31.   Exit
  32.  
  33. /* Set security info */
  34. Say;Say 'Enter userid, followed by password:'
  35. Parse Upper LineIn uidpw
  36. uidpw = Space(Translate(uidpw,' ',','))
  37.  
  38. If uidpw = '*' Then
  39.   si = 'None'
  40. Else
  41.   Do
  42.   If Words(uidpw) <> 2 Then
  43.     Do
  44.     Say 'You must supply both a userid and a password.'
  45.     Exit
  46.     End
  47.   Parse Var uidpw uid pw .
  48.   si = 'Pgm' uid pw
  49.   End
  50.  
  51. call syscls
  52.  
  53. appcrc = Appc('Tp_Started', loclu, 'REMCMDC1', 'inf.')
  54. If appcrc <> 0 Then
  55.   Do;Say;Say 'Tp_Started failed with rc='xlatrxap(appcrc)
  56.   Exit
  57.   End
  58. tpid = inf.0
  59. Signal On Syntax Name Trap_Allocate_Syntax
  60. appcrc = Appc('Allocate',tpid,partlu,'#INTER','REMCMDC3','Mapped',
  61.               , 'A','N',si,'Inf.')
  62. Signal Off Syntax
  63. If appcrc <> 0 Then
  64.   Do;Say;Say 'Mc_Allocate failed with rc='xlatrxap(appcrc)'.'
  65.   Say 'Primary Rc  ='c2x(inf.2);
  66.   Say 'Secondary Rc='c2x(inf.3)
  67.   Say 'Sense Code  ='c2x(inf.4)
  68.   Call Appc 'Tp_Ended', tpid
  69.   Exit
  70.   End
  71. convid = inf.1
  72. appcrc = Appc('Send_Data', tpid, convid, 'Mapped', Cryption(uid pw))
  73. If appcrc <> 0 Then
  74.   Do;Say;Say 'Send_Data (uid/pw) failed with rc='xlatrxap(appcrc)'.'
  75.   Call Appc 'Tp_Ended', tpid
  76.   Exit
  77.   End
  78.  
  79. appcrc = Appc('Flush', tpid,convid, 'Mapped')
  80. If appcrc <> 0 Then
  81.   Do;Say;Say 'Flush (uid/pw) failed with rc='xlatrxap(appcrc)'.'
  82.   Call Appc 'Tp_Ended', tpid
  83.   Exit
  84.   End
  85.  
  86. If rxpmprintf(pq,' ') = 0 Then
  87.   Do
  88.   Call rxstartsession 'pmprintf.exe','queue' pq,'Child'
  89.   call syssleep 3
  90.   End
  91.  
  92. call rxcreaterexxthread 'remcmdc2', pq
  93.  
  94. Do Forever
  95.   call syscls
  96.   Say Center('Issuing Commands at Remote Workstation "'partlu'"',50)
  97.   Say;Say 'Enter string to be interpreted by Rexx on remote workstation:'
  98.   Say '(Type * to terminate)'
  99.   Parse LineIn cmdstr
  100.   If cmdstr = '*' Then
  101.     Leave
  102.   If cmdstr = '' Then
  103.     cmdstr = ' '
  104.   Call Process_CmdStr
  105. End
  106.  
  107. Call Appc 'Deallocate', tpid, convid, 'Mapped', 'Sync_Level'
  108. Call Appc 'Tp_Ended', tpid
  109.  
  110. Exit
  111.  
  112. /* ======================================================================= */
  113. /* Process Command String                                                  */
  114. /* ======================================================================= */
  115. Process_CmdStr:
  116.  
  117. appcrc = Appc('Send_Data', tpid, convid, 'Mapped', Cryption(cmdstr))
  118. If appcrc <> 0 Then
  119.   Do;Say;Say 'Send_Data failed with rc='xlatrxap(appcrc)'.'
  120.   Call Appc 'Tp_Ended', tpid
  121.   Exit
  122.   End
  123.  
  124. appcrc = Appc('Flush', tpid, convid, 'Mapped')
  125. If appcrc <> 0 Then
  126.   Do;Say;Say 'Flush failed with rc='xlatrxap(appcrc)'.'
  127.   Call Appc 'Tp_Ended', tpid
  128.   Exit
  129.   End
  130.  
  131. Return
  132.  
  133. Trap_Allocate_Syntax:
  134. Say 'Partner LU name' partlu 'is invalid.'
  135. Say 'It must be either an lu-alias (1-8 chars), or a fully qualified name'
  136. Say '(1-8 char network name, a period, and a 1-8 char lu-name).'
  137. Address 'CMD' '@PAUSE'
  138. Exit
  139.  
  140. Cryption:
  141. Return BitXor(Arg(1),Copies('ff'x,Length(Arg(1))))
  142.  
  143. /* Define call-back TP */
  144. Define_Callback_Tp:
  145.  
  146. progfile = ''
  147.  
  148. Drop tp.
  149. tp.2  = 'REMCMDC2' /* tp name */
  150. tp.3  = progfile   /* tp filespec */
  151. tp.4  = ''         /* argument */
  152. tp.5  = ''         /* icon filespec */
  153. tp.6  = 'mapped'   /* conv type */
  154. tp.7  = 'no'       /* conv security */
  155. tp.8  = 'none'     /* sync level */
  156. tp.9  = 'Operator_Started' /* how to run program */
  157. tp.10 = 'Vio_windowable' /* program type */
  158. tp.11 = 1  /* queue_depth_limit */
  159. tp.12 = 'infinite' /* incoming_alloc_timeout */
  160. tp.13 = 'infinite' /* receive_alloc_timeout */
  161. acsrc = rxacsmgt('define_tp','tp.')
  162. If acsrc <> 0 Then
  163.   Do
  164.   Call rxpmprintf pq,'Define_Tp for REMCMDC2 failed with acsrc =' acsrc
  165.   Exit
  166.   End
  167. Return
  168.