---
title: "Ant-sshexec-执行远程服务器或本地脚本"
author: "aryanwang"
date: "2012-02-17T15:35:10Z"
tags: []
categories: ["研发管理"]
slug: "ant-sshexec"
draft: false
lastmod: "2012-02-17T15:42:29Z"
id: 1409542
url: "https://keepmoving2012.iteye.com/blog/1409542"
---

**1. 远程服务器**

 

 

 

Reference:[http://ant.apache.org/manual/Tasks/sshexec.html](http://ant.apache.org/manual/Tasks/sshexec.html)

 

Runs a command on a remote machine running SSH daemon.

**Note:** This task depends on external libraries not included in the Ant distribution. See [Library Dependencies](http://ant.apache.org/manual/install.html#librarydependencies) for more information. This task has been tested with jsch-0.1.29 and above and won't work with versions of jsch earlier than 0.1.28.

执行这个命令的时候需要下载第三方依赖包jsch-0.1.46.jar到ant/lib目录。

 

 

```
<sshexec 
    host="${host}"
    username="${usr}"   
    password="${pwd}"
    trust="true" 
    command="pwd;./test.sh" 
    outputproperty="output"
/>
```

 

 

 

这样在后续的ant脚本中就可以用${output}来取得脚本的运行结果了。

 

 

**2.本地脚本**

[Reference : http://ant.apache.org/manual/Tasks/exec.html](http://ant.apache.org/manual/Tasks/exec.html)

 

```
<exec 
    dir="${tools.dir}" 
    executable="xx.sh或xx.bat或xx.exe" 
    outputproperty="platform.type" 
/> 
```

 

 

 

这样在后续的ant脚本中就可以用${platform.type}来取得脚本的运行结果了。