`

解决ant scp/sshexec任务调用问题

阅读更多

问题1:关于known_hosts问题

 

	<target name="scp-file">
		<scp file="add.jsp" todir="root:root2013@192.168.1.154:/root/my"  >

		</scp>
	</target>

 

       执行scp或sshexec任务过程中出现com.jcraft.jsch.JSchException: reject HostKey或者

com.jcraft.jsch.JSchException: java.io.FileNotFoundException: ~\.ssh\known_hosts (系统找不到指定的路径。)

 

解决办法:加入trust属性并设置为true

 

 

	<target name="scp-file">
		<scp file="add.jsp" todir="root:root2013@192.168.1.154:/root/my" trust="true" >

		</scp>
	</target>

 

  

    trust属性一般设置为true, 如果为默认值false时,那么就要求你所连接的host必须存在于你的knownhosts文件中,并且这个文件也必须是存在的

 

问题2:执行 Ant sshexec 时,出现 command not found

 

 

	<target name="sshexec1">
	      <sshexec host="192.168.1.249" username="root"  password="123456"
	         trust="true" command="jps -v"/>
	</target>

 

 

 

 

 解决办法:执行命令前面加上:source /etc/profile ~/.profile ~/.bash_profile

 

 

	<target name="sshexec1">
	      <sshexec host="192.168.1.249" username="root"  password="123456"
	         trust="true" command="source /etc/profile ~/.profile ~/.bash_profile &amp;&amp; jps -v"/>
	</target>

 

 

 

       ant的sshexec连接的时候,是不会执行/etc/profile ~/.profile ~/.bash_profile的,于是这个会话当中就有可能找不到某些Command了

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics