hadoop.cmd 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. @echo off
  2. @rem Licensed to the Apache Software Foundation (ASF) under one or more
  3. @rem contributor license agreements. See the NOTICE file distributed with
  4. @rem this work for additional information regarding copyright ownership.
  5. @rem The ASF licenses this file to You under the Apache License, Version 2.0
  6. @rem (the "License"); you may not use this file except in compliance with
  7. @rem the License. You may obtain a copy of the License at
  8. @rem
  9. @rem http://www.apache.org/licenses/LICENSE-2.0
  10. @rem
  11. @rem Unless required by applicable law or agreed to in writing, software
  12. @rem distributed under the License is distributed on an "AS IS" BASIS,
  13. @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. @rem See the License for the specific language governing permissions and
  15. @rem limitations under the License.
  16. @rem This script runs the hadoop core commands.
  17. @rem Environment Variables
  18. @rem
  19. @rem JAVA_HOME The java implementation to use. Overrides JAVA_HOME.
  20. @rem
  21. @rem HADOOP_CLASSPATH Extra Java CLASSPATH entries.
  22. @rem
  23. @rem HADOOP_USER_CLASSPATH_FIRST When defined, the HADOOP_CLASSPATH is
  24. @rem added in the beginning of the global
  25. @rem classpath. Can be defined, for example,
  26. @rem by doing
  27. @rem export HADOOP_USER_CLASSPATH_FIRST=true
  28. @rem
  29. @rem HADOOP_HEAPSIZE The maximum amount of heap to use, in MB.
  30. @rem Default is 1000.
  31. @rem
  32. @rem HADOOP_OPTS Extra Java runtime options.
  33. @rem
  34. @rem HADOOP_CLIENT_OPTS when the respective command is run.
  35. @rem HADOOP_{COMMAND}_OPTS etc HADOOP_JT_OPTS applies to JobTracker
  36. @rem for e.g. HADOOP_CLIENT_OPTS applies to
  37. @rem more than one command (fs, dfs, fsck,
  38. @rem dfsadmin etc)
  39. @rem
  40. @rem HADOOP_CONF_DIR Alternate conf dir. Default is ${HADOOP_HOME}/conf.
  41. @rem
  42. @rem HADOOP_ROOT_LOGGER The root appender. Default is INFO,console
  43. @rem
  44. if not defined HADOOP_BIN_PATH (
  45. set HADOOP_BIN_PATH=%~dp0
  46. )
  47. if "%HADOOP_BIN_PATH:~-1%" == "\" (
  48. set HADOOP_BIN_PATH=%HADOOP_BIN_PATH:~0,-1%
  49. )
  50. call :updatepath %HADOOP_BIN_PATH%
  51. :main
  52. setlocal enabledelayedexpansion
  53. set DEFAULT_LIBEXEC_DIR=%HADOOP_BIN_PATH%\..\libexec
  54. if not defined HADOOP_LIBEXEC_DIR (
  55. set HADOOP_LIBEXEC_DIR=%DEFAULT_LIBEXEC_DIR%
  56. )
  57. call %HADOOP_LIBEXEC_DIR%\hadoop-config.cmd %*
  58. if "%1" == "--config" (
  59. shift
  60. shift
  61. )
  62. set hadoop-command=%1
  63. if not defined hadoop-command (
  64. goto print_usage
  65. )
  66. call :make_command_arguments %*
  67. set hdfscommands=namenode secondarynamenode datanode dfs dfsadmin fsck balancer fetchdt oiv dfsgroups
  68. for %%i in ( %hdfscommands% ) do (
  69. if %hadoop-command% == %%i set hdfscommand=true
  70. )
  71. if defined hdfscommand (
  72. @echo DEPRECATED: Use of this script to execute hdfs command is deprecated. 1>&2
  73. @echo Instead use the hdfs command for it. 1>&2
  74. if exist %HADOOP_HDFS_HOME%\bin\hdfs.cmd (
  75. call %HADOOP_HDFS_HOME%\bin\hdfs.cmd %*
  76. goto :eof
  77. ) else if exist %HADOOP_HOME%\bin\hdfs.cmd (
  78. call %HADOOP_HOME%\bin\hdfs.cmd %*
  79. goto :eof
  80. ) else (
  81. echo HADOOP_HDFS_HOME not found!
  82. goto :eof
  83. )
  84. )
  85. set mapredcommands=pipes job queue mrgroups mradmin jobtracker tasktracker
  86. for %%i in ( %mapredcommands% ) do (
  87. if %hadoop-command% == %%i set mapredcommand=true
  88. )
  89. if defined mapredcommand (
  90. @echo DEPRECATED: Use of this script to execute mapred command is deprecated. 1>&2
  91. @echo Instead use the mapred command for it. 1>&2
  92. if exist %HADOOP_MAPRED_HOME%\bin\mapred.cmd (
  93. call %HADOOP_MAPRED_HOME%\bin\mapred.cmd %*
  94. goto :eof
  95. ) else if exist %HADOOP_HOME%\bin\mapred.cmd (
  96. call %HADOOP_HOME%\bin\mapred.cmd %*
  97. goto :eof
  98. ) else (
  99. echo HADOOP_MAPRED_HOME not found!
  100. goto :eof
  101. )
  102. )
  103. if %hadoop-command% == classpath (
  104. @echo %CLASSPATH%
  105. goto :eof
  106. )
  107. set corecommands=fs version jar distcp daemonlog archive
  108. for %%i in ( %corecommands% ) do (
  109. if %hadoop-command% == %%i set corecommand=true
  110. )
  111. if defined corecommand (
  112. call :%hadoop-command%
  113. ) else (
  114. set CLASSPATH=%CLASSPATH%;%CD%
  115. set CLASS=%hadoop-command%
  116. )
  117. set path=%PATH%;%HADOOP_BIN_PATH%
  118. @rem Always respect HADOOP_OPTS and HADOOP_CLIENT_OPTS
  119. set HADOOP_OPTS=%HADOOP_OPTS% %HADOOP_CLIENT_OPTS%
  120. @rem make sure security appender is turned off
  121. if not defined HADOOP_SECURITY_LOGGER (
  122. set HADOOP_SECURITY_LOGGER=INFO,NullAppender
  123. )
  124. set HADOOP_OPTS=%HADOOP_OPTS% -Dhadoop.security.logger=%HADOOP_SECURITY_LOGGER%
  125. call %JAVA% %JAVA_HEAP_MAX% %HADOOP_OPTS% -classpath %CLASSPATH% %CLASS% %hadoop-command-arguments%
  126. goto :eof
  127. :fs
  128. set CLASS=org.apache.hadoop.fs.FsShell
  129. goto :eof
  130. :version
  131. set CLASS=org.apache.hadoop.util.VersionInfo
  132. goto :eof
  133. :jar
  134. set CLASS=org.apache.hadoop.util.RunJar
  135. goto :eof
  136. :distcp
  137. set CLASS=org.apache.hadoop.tools.DistCp
  138. set CLASSPATH=%CLASSPATH%;%TOOL_PATH%
  139. goto :eof
  140. :daemonlog
  141. set CLASS=org.apache.hadoop.log.LogLevel
  142. goto :eof
  143. :archive
  144. set CLASS=org.apache.hadoop.tools.HadoopArchives
  145. set CLASSPATH=%CLASSPATH%;%TOOL_PATH%
  146. goto :eof
  147. :updatepath
  148. set path_to_add=%*
  149. set current_path_comparable=%path%
  150. set current_path_comparable=%current_path_comparable: =_%
  151. set current_path_comparable=%current_path_comparable:(=_%
  152. set current_path_comparable=%current_path_comparable:)=_%
  153. set path_to_add_comparable=%path_to_add%
  154. set path_to_add_comparable=%path_to_add_comparable: =_%
  155. set path_to_add_comparable=%path_to_add_comparable:(=_%
  156. set path_to_add_comparable=%path_to_add_comparable:)=_%
  157. for %%i in ( %current_path_comparable% ) do (
  158. if /i "%%i" == "%path_to_add_comparable%" (
  159. set path_to_add_exist=true
  160. )
  161. )
  162. set system_path_comparable=
  163. set path_to_add_comparable=
  164. if not defined path_to_add_exist path=%path_to_add%;%path%
  165. set path_to_add=
  166. goto :eof
  167. @rem This changes %1, %2 etc. Hence those cannot be used after calling this.
  168. :make_command_arguments
  169. if "%1" == "--config" (
  170. shift
  171. shift
  172. )
  173. if [%2] == [] goto :eof
  174. shift
  175. set _arguments=
  176. :MakeCmdArgsLoop
  177. if [%1]==[] goto :EndLoop
  178. if not defined _arguments (
  179. set _arguments=%1
  180. ) else (
  181. set _arguments=!_arguments! %1
  182. )
  183. shift
  184. goto :MakeCmdArgsLoop
  185. :EndLoop
  186. set hadoop-command-arguments=%_arguments%
  187. goto :eof
  188. :print_usage
  189. @echo Usage: hadoop [--config confdir] COMMAND
  190. @echo where COMMAND is one of:
  191. @echo fs run a generic filesystem user client
  192. @echo version print the version
  193. @echo jar ^<jar^> run a jar file
  194. @echo distcp ^<srcurl^> ^<desturl^> copy file or directories recursively
  195. @echo archive -archiveName NAME -p ^<parent path^> ^<src^>* ^<dest^> create a hadoop archive
  196. @echo classpath prints the class path needed to get the
  197. @echo Hadoop jar and the required libraries
  198. @echo daemonlog get/set the log level for each daemon
  199. @echo or
  200. @echo CLASSNAME run the class named CLASSNAME
  201. @echo.
  202. @echo Most commands print help when invoked w/o parameters.
  203. endlocal