Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for 4allmembers.cmd

(view source code of 4allmembers.cmd as plain text)

  1. /* Execute a command For All group Members */
  2.  
  3.  
  4. /* Command line parsing */
  5. parse arg group commandline
  6. if left( group, 1 ) = '"' then parse arg '"'group'"' commandline
  7. if pos( "?", group ) > 0 then call Syntax
  8. if commandline = ""  then call Syntax
  9.  
  10.  
  11. /* Initialize RexxUtil */
  12. if RxFuncQuery( "SysLoadFuncs" ) <> 0 then do
  13. 	call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  14. 	call SysLoadFuncs
  15. end
  16.  
  17.  
  18. /* Initialize LAN Server RexxUtil */
  19. if RxFuncQuery( "LoadLsRxutFuncs" ) <> 0 then do
  20. 	call RxFuncAdd "LoadLsRxutFuncs", "LSRxUt", "LoadLsRxutFuncs"
  21. 	call LoadLsRxutFuncs
  22. end
  23.  
  24.  
  25. /* Get the requester type (Server, Peer or Requester)         */
  26. /* If it is not a peer server, get the domain controller name */
  27. ReqType = RequesterType()
  28. if ReqType = "PEER" then do
  29. 	SrvName = ""
  30. end
  31. else do
  32. 	SrvName = GetDC()
  33. end
  34.  
  35. /* List all users from the specified group */
  36. NETGROUPUSERS = 340
  37. myRc = NetGetInfo( NETGROUPUSERS, "groupInfo", SrvName, group )
  38. if myRc <> "0" then do
  39. 	say "NetGetInfo NETGROUPUSERS "||myRc
  40. 	EXIT 1
  41. end
  42.  
  43.  
  44. /* Execute specified command for each user from specified group */
  45. do i=1 to groupInfo.0
  46. 	fullcommand = commandline
  47. 	/* Substitute user ID for "#" */
  48. 	do until upos = 0
  49. 		upos = pos( "#", fullcommand )
  50. 		if upos > 0 then do
  51. 			fullcommand = substr( fullcommand, 1, upos - 1 )||,
  52. 			              groupInfo.i||,
  53. 			              substr( fullcommand, upos + 1 )
  54. 		end
  55. 	end
  56. 	/* Execute command */
  57. 	address CMD "@CMD /C "||fullcommand
  58. end
  59. EXIT 0
  60.  
  61.  
  62. /* Get domain controller name */
  63. GetDC: procedure
  64. 	NETGETDCNAME = 510
  65. 	DomainName = value( "DOMAIN", , "OS2ENVIRONMENT" )
  66. 	parse value NetMisc( NETGETDCNAME, DomainName, "" ) with myRc dcName
  67. 	if myRc <> "0" then do
  68. 		say "NetMisc NETGETDCNAME error: "||myRc
  69. 		exit 9
  70. 	end
  71. return dcName
  72.  
  73.  
  74. /* Get requester type */
  75. RequesterType:
  76. 	NETSERVICE = 170
  77. 	MyRc = NetEnumerate( NETSERVICE, "serviceInfo", "" )
  78. 	if MyRc <> 0 then do
  79. 		say "NetEnumerate NETSERVICE error: "||MyRc
  80. 		exit 9
  81. 	end
  82. 	if serviceInfo.0 = 0 then do
  83. 		req_type = "UNKNOWN"
  84. 	end
  85. 	else do
  86. 		req_type = ""
  87. 		do i = 1 to serviceInfo.0
  88. 			if serviceInfo.i = "SERVER" then req_type = "SERVER"
  89. 		end
  90. 		if req_type = "" then do i = 1 to serviceInfo.0
  91. 			if serviceInfo.i = "PEER" then req_type = "PEER"
  92. 		end
  93. 		if req_type = "" then do i = 1 to serviceInfo.0
  94. 			if serviceInfo.i = "REQUESTER" then req_type = "REQUESTER"
  95. 		end
  96. 	end
  97. return req_type
  98.  
  99.  
  100. /* Help message */
  101. Syntax: procedure
  102. 	say
  103. 	say "4AllMembers,  Version 1.00 for OS/2"
  104. 	say "Executes a command once for every member of a specified group"
  105. 	say "Written by Rob van der Woude"
  106. 	say
  107. 	say "Usage:  4ALLMEMBERS  <group>  <command>  [ <parameters> ]"
  108. 	say
  109. 	say '"#" characters in <parameters> will be substituted'
  110. 	say "by the user ID when <command> is executed"
  111. 	say
  112. 	say "Set the environment variable DOMAIN=<logon_domain>"
  113. 	say "when using this Rexx script in a LAN Server environment"
  114. 	EXIT 1
  115. return
  116.  

page last modified: 2024-04-16; loaded in 0.0132 seconds