Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for 4allctxsrv.bat

(view source code of 4allctxsrv.bat as plain text)

  1. @ECHO OFF
  2. :: Check Windows version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4.  
  5. :: At least 2 command line arguments are required
  6. IF [%2]==[] GOTO Syntax
  7.  
  8. :: Use local variables
  9. SETLOCAL ENABLEEXTENSIONS
  10.  
  11. :: :: :: :: :: :: :: :: :: :: :: :: :: ::
  12. :: Specify 1 Citrix server in the farm ::
  13. :: :: :: :: :: :: :: :: :: :: :: :: :: ::
  14. SET CtxSrv=MYCTXSRV01
  15.  
  16. :: Check if the server is online
  17. PING %CtxSrv% -n 1 >NUL 2>&1
  18. IF ERRORLEVEL 1 (
  19. 	ECHO.
  20. 	ECHO Server \\%CtxSrv% is not available
  21. 	GOTO Syntax
  22. )
  23.  
  24. :: Main command; delims is an asterisc, followed by a tab and a space
  25. :: Change "TCP/IP" search string if other protocols are used
  26. FOR /F "tokens=1 delims=*	 " %%A IN ('PSEXEC \\%CtxSrv% QUERY FARM /CONTINUE 2^>NUL ^| FIND "TCP/IP" ^| SORT') DO CALL :MyCommand %%A %*
  27.  
  28. :: Done
  29. ENDLOCAL
  30. GOTO End
  31.  
  32.  
  33. :MyCommand
  34. :: Use local variables, for this server only
  35. SETLOCAL
  36. :: First argument is server name
  37. SET Server=%1
  38. :: The rest is the command
  39. FOR /F "tokens=1*" %%X IN ('ECHO.%*') DO SET MyCommand=%%Y
  40. :: Substitute server name for # in command
  41. CALL SET MyCommand=%%MyCommand:#=%Server%%%
  42. :: Execute the resulting command
  43. %COMSPEC% /C %MyCommand%
  44. :: End subroutine
  45. ENDLOCAL
  46. GOTO:EOF
  47.  
  48.  
  49. :Syntax
  50. ECHO.
  51. ECHO 4AllCtxSrv.bat,  Version 1.12 for Windows 2000
  52. ECHO Execute a command once for each server of a Citrix farm
  53. ECHO.
  54. ECHO Usage:    4AllCtxSrv  my_command  [ arguments ]
  55. ECHO.
  56. ECHO Where:    "my_command" will be executed once for each server in the farm.
  57. ECHO           "arguments"  is the list of command line arguments for my_command.
  58. ECHO           "#"          in command line arguments is substituted by server name.
  59. ECHO.
  60. ECHO Example:  4AllCtxSrv  echo  #
  61. ECHO.
  62. ECHO The server list is retrieved from a hardcoded Citrix server;
  63. ECHO modify this server name before using this batch file for the first time.
  64. ECHO.
  65. ECHO Uses SysInternals's PSEXEC, available at http://www.sysinternals.com
  66. ECHO.
  67. ECHO Written by Rob van der Woude
  68. ECHO http://www.robvanderwoude.com
  69.  
  70. :End
  71.  

page last modified: 2024-02-26; loaded in 0.0143 seconds