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.4 KiB

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