You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sshexec.html 6.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>SSHEXEC Task</title>
  20. </head>
  21. <body>
  22. <h2><a name="sshexec">SSHEXEC</a></h2>
  23. <h3>Description</h3>
  24. <p><em>since Ant 1.6</em></p>
  25. <p>Runs a command on a remote machine running SSH daemon.
  26. </p>
  27. <p><b>Note:</b> This task depends on external libraries not included
  28. in the Ant distribution. See <a
  29. href="../install.html#librarydependencies">Library Dependencies</a>
  30. for more information. This task has been tested with jsch-0.1.29 and above
  31. and won't work with versions of jsch earlier than
  32. 0.1.28.</p>
  33. <p>See also the <a href="scp.html">scp task</a></p>
  34. <h3>Parameters</h3>
  35. <table border="1" cellpadding="2" cellspacing="0">
  36. <tr>
  37. <td valign="top"><b>Attribute</b></td>
  38. <td valign="top"><b>Description</b></td>
  39. <td align="center" valign="top"><b>Required</b></td>
  40. </tr>
  41. <tr>
  42. <td valign="top">host</td>
  43. <td valign="top">The hostname or IP address of the remote host to which you wish to connect.</td>
  44. <td valign="top" align="center">Yes</td>
  45. </tr>
  46. <tr>
  47. <td valign="top">username</td>
  48. <td valign="top">The username on the remote host to which you are connecting.</td>
  49. <td valign="top" align="center">Yes</td>
  50. </tr>
  51. <tr>
  52. <td valign="top">command</td>
  53. <td valign="top">The command to run on the remote host.</td>
  54. <td valian="top" align="center">Yes</td>
  55. </tr>
  56. <tr>
  57. <td valign="top">port</td>
  58. <td valign="top">The port to connect to on the remote host.</td>
  59. <td valian="top" align="center">No, defaults to 22.</td>
  60. </tr>
  61. <tr>
  62. <td valign="top">trust</td>
  63. <td valign="top">This trusts all unknown hosts if set to yes/true.<br>
  64. <strong>Note</strong> If you set this to false (the default), the
  65. host you connect to must be listed in your knownhosts file, this
  66. also implies that the file exists.</td>
  67. <td valian="top" align="center">No, defaults to No.</td>
  68. </tr>
  69. <tr>
  70. <td valign="top">knownhosts</td>
  71. <td valign="top">This sets the known hosts file to use to validate
  72. the identity of the remote host. This must be a SSH2 format file.
  73. SSH1 format is not supported.</td>
  74. <td valian="top" align="center">No, defaults to
  75. ${user.home}/.ssh/known_hosts.</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">failonerror</td>
  79. <td valign="top">Whether to halt the build if the command does not complete successfully.
  80. </td>
  81. <td valign="top" align="center">No; defaults to true.</td>
  82. </tr>
  83. <tr>
  84. <td valign="top">password</td>
  85. <td valign="top">The password.</td>
  86. <td valign="top" align="center">Not if you are using key based
  87. authentication or the password has been given in the file or
  88. todir attribute.</td>
  89. </tr>
  90. <tr>
  91. <td valign="top">keyfile</td>
  92. <td valign="top">Location of the file holding the private key.</td>
  93. <td valign="top" align="center">Yes, if you are using key based
  94. authentication.</td>
  95. </tr>
  96. <tr>
  97. <td valign="top">passphrase</td>
  98. <td valign="top">Passphrase for your private key.</td>
  99. <td valign="top" align="center">No, defaults to an empty string.</td>
  100. </tr>
  101. <tr>
  102. <td valign="top">output</td>
  103. <td valign="top">Name of a file to which to write the output.</td>
  104. <td align="center" valign="top">No</td>
  105. </tr>
  106. <tr>
  107. <td valign="top">append</td>
  108. <td valign="top">Whether output file should be appended to or overwritten. Defaults to false, meaning overwrite any existing file.</td>
  109. <td align="center" valign="top">No</td>
  110. </tr>
  111. <tr>
  112. <td valign="top">outputproperty</td>
  113. <td valign="top">The name of a property in which the output of the
  114. command should be stored.</td>
  115. <td align="center" valign="top">No</td>
  116. </tr>
  117. <tr>
  118. <td valign="top">timeout</td>
  119. <td valign="top">Stop the command if it doesn't finish within the
  120. specified time (given in milliseconds). Defaults to 0 which means &quot;wait forever&quot;.</td>
  121. <td align="center" valign="top">No</td>
  122. </tr>
  123. </table>
  124. <h3>Examples</h3>
  125. <p><b>Run a command on a remote machine using password authentication</b></p>
  126. <pre>
  127. &lt;sshexec host=&quot;somehost&quot;
  128. username=&quot;dude&quot;
  129. password=&quot;yo&quot;
  130. command=&quot;touch somefile&quot;/&gt;
  131. </pre>
  132. <p><b>Run a command on a remote machine using key authentication</b></p>
  133. <pre>
  134. &lt;sshexec host=&quot;somehost&quot;
  135. username=&quot;dude&quot;
  136. keyfile=&quot;${user.home}/.ssh/id_dsa&quot;
  137. passphrase=&quot;yo its a secret&quot;
  138. command=&quot;touch somefile&quot;/&gt;
  139. </pre>
  140. <p><b>Run a command on a remote machine using key authentication with no passphrase</b></p>
  141. <pre>
  142. &lt;sshexec host=&quot;somehost&quot;
  143. username=&quot;dude&quot;
  144. keyfile=&quot;${user.home}/.ssh/id_dsa&quot;
  145. command=&quot;touch somefile&quot;/&gt;
  146. </pre>
  147. <p><strong>Security Note:</strong> Hard coding passwords and/or usernames
  148. in sshexec task can be a serious security hole. Consider using variable
  149. substitution and include the password on the command line. For example:<br>
  150. <pre>
  151. &lt;sshexec host=&quot;somehost&quot;
  152. username=&quot;${username}&quot;
  153. password=&quot;${password}&quot;
  154. command=&quot;touch somefile&quot;/&gt;
  155. </pre>
  156. Invoke ant with the following command line:
  157. <pre>
  158. ant -Dusername=me -Dpassword=mypassword target1 target2
  159. </pre>
  160. </p>
  161. </body>
  162. </html>