hadoop.cmd 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. if not defined hadoop-command-arguments (
  105. @rem No need to bother starting up a JVM for this simple case.
  106. @echo %CLASSPATH%
  107. exit /b
  108. )
  109. )
  110. set corecommands=fs version jar checknative distcp daemonlog archive classpath credential key
  111. for %%i in ( %corecommands% ) do (
  112. if %hadoop-command% == %%i set corecommand=true
  113. )
  114. if defined corecommand (
  115. call :%hadoop-command%
  116. ) else (
  117. set CLASSPATH=%CLASSPATH%;%CD%
  118. set CLASS=%hadoop-command%
  119. )
  120. set path=%PATH%;%HADOOP_BIN_PATH%
  121. @rem Always respect HADOOP_OPTS and HADOOP_CLIENT_OPTS
  122. set HADOOP_OPTS=%HADOOP_OPTS% %HADOOP_CLIENT_OPTS%
  123. @rem make sure security appender is turned off
  124. if not defined HADOOP_SECURITY_LOGGER (
  125. set HADOOP_SECURITY_LOGGER=INFO,NullAppender
  126. )
  127. set HADOOP_OPTS=%HADOOP_OPTS% -Dhadoop.security.logger=%HADOOP_SECURITY_LOGGER%
  128. call %JAVA% %JAVA_HEAP_MAX% %HADOOP_OPTS% -classpath %CLASSPATH% %CLASS% %hadoop-command-arguments%
  129. exit /b %ERRORLEVEL%
  130. :fs
  131. set CLASS=org.apache.hadoop.fs.FsShell
  132. goto :eof
  133. :version
  134. set CLASS=org.apache.hadoop.util.VersionInfo
  135. goto :eof
  136. :jar
  137. set CLASS=org.apache.hadoop.util.RunJar
  138. goto :eof
  139. :checknative
  140. set CLASS=org.apache.hadoop.util.NativeLibraryChecker
  141. goto :eof
  142. :distcp
  143. set CLASS=org.apache.hadoop.tools.DistCp
  144. set CLASSPATH=%CLASSPATH%;%TOOL_PATH%
  145. goto :eof
  146. :daemonlog
  147. set CLASS=org.apache.hadoop.log.LogLevel
  148. goto :eof
  149. :archive
  150. set CLASS=org.apache.hadoop.tools.HadoopArchives
  151. set CLASSPATH=%CLASSPATH%;%TOOL_PATH%
  152. goto :eof
  153. :classpath
  154. set CLASS=org.apache.hadoop.util.Classpath
  155. goto :eof
  156. :credential
  157. set CLASS=org.apache.hadoop.security.alias.CredentialShell
  158. goto :eof
  159. :key
  160. set CLASS=org.apache.hadoop.crypto.key.KeyShell
  161. goto :eof
  162. :updatepath
  163. set path_to_add=%*
  164. set current_path_comparable=%path%
  165. set current_path_comparable=%current_path_comparable: =_%
  166. set current_path_comparable=%current_path_comparable:(=_%
  167. set current_path_comparable=%current_path_comparable:)=_%
  168. set path_to_add_comparable=%path_to_add%
  169. set path_to_add_comparable=%path_to_add_comparable: =_%
  170. set path_to_add_comparable=%path_to_add_comparable:(=_%
  171. set path_to_add_comparable=%path_to_add_comparable:)=_%
  172. for %%i in ( %current_path_comparable% ) do (
  173. if /i "%%i" == "%path_to_add_comparable%" (
  174. set path_to_add_exist=true
  175. )
  176. )
  177. set system_path_comparable=
  178. set path_to_add_comparable=
  179. if not defined path_to_add_exist path=%path_to_add%;%path%
  180. set path_to_add=
  181. goto :eof
  182. @rem This changes %1, %2 etc. Hence those cannot be used after calling this.
  183. :make_command_arguments
  184. if "%1" == "--config" (
  185. shift
  186. shift
  187. )
  188. if [%2] == [] goto :eof
  189. shift
  190. set _arguments=
  191. :MakeCmdArgsLoop
  192. if [%1]==[] goto :EndLoop
  193. if not defined _arguments (
  194. set _arguments=%1
  195. ) else (
  196. set _arguments=!_arguments! %1
  197. )
  198. shift
  199. goto :MakeCmdArgsLoop
  200. :EndLoop
  201. set hadoop-command-arguments=%_arguments%
  202. goto :eof
  203. :print_usage
  204. @echo Usage: hadoop [--config confdir] COMMAND
  205. @echo where COMMAND is one of:
  206. @echo fs run a generic filesystem user client
  207. @echo version print the version
  208. @echo jar ^<jar^> run a jar file
  209. @echo checknative [-a^|-h] check native hadoop and compression libraries availability
  210. @echo distcp ^<srcurl^> ^<desturl^> copy file or directories recursively
  211. @echo archive -archiveName NAME -p ^<parent path^> ^<src^>* ^<dest^> create a hadoop archive
  212. @echo classpath prints the class path needed to get the
  213. @echo Hadoop jar and the required libraries
  214. @echo credential interact with credential providers
  215. @echo key manage keys via the KeyProvider
  216. @echo daemonlog get/set the log level for each daemon
  217. @echo or
  218. @echo CLASSNAME run the class named CLASSNAME
  219. @echo.
  220. @echo Most commands print help when invoked w/o parameters.
  221. endlocal