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 5.3 KiB

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