ZKX's LAB

怎么用java代码调用远程Linux上的shell脚本 shell远程调用脚本命令行

2021-04-08知识7

shell脚本中,用expect命令如何实现自动远程操作,折磨我好久了.. 既然$无法匹配,我觉得你完全可以单独配置一个环境变量,比如说我登录到服务器后echo\"SCPGOGOGOexpect捕获到SCPGOGOGO 开始执行scpexpect好久不写了,不知道$?判断怎么写,如果要写我的翻书了。当判断$?为真,然后执行send\"java-jar。不过我想在仔细思考一下可能会有更好的逻辑。我不太稀饭expect这种交互写法。因为有更多简单便捷的方法,不知道你为什么不用。sshpass ssh密钥 简单点直接用sh操作ssh就可以达到你想要的效果,why死扣expect?各种集中式管理软件(puppet,salt,ansible.)都是为了方便远程操作管理的东西why?不用?本来1小时解决的问题,死扣expect花了好几天,这种把一个问题发展到解决2个问题的做事方法不可取。

shell 在脚本中直接调用函数和在命令行调用有什么区别 你写的这shell执行起来不需要命令行参数,你这没结果是因为,你没执行此函数,只要在下面加上echo_hello就行了 查看原帖>;>;

怎么用java代码调用远程Linux上的shell脚本 package org.shirdrn.shell;import java.io.IOException;import java.io.InputStream;import java.nio.charset.Charset;import ch.ethz.ssh2.Connection;import ch.ethz.ssh2.Session;远程Shell脚本执行工具author Administratorpublic class RemoteShellTool {private Connection conn;private String ipAddr;private String charset=Charset.defaultCharset().toString();private String userName;private String password;public RemoteShellTool(String ipAddr,String userName,String password,String charset){this.ipAddr=ipAddr;this.userName=userName;this.password=password;if(charset。null){this.charset=charset;}}登录远程Linux主机returnthrows IOExceptionpublic boolean login()throws IOException {conn=new Connection(ipAddr);conn.connect();连接return conn.authenticateWithPassword(userName,password);认证}执行Shell脚本或命令param cmds 命令行序列returnpublic String exec(String cmds){InputStream in=null;String result=\";try {if(this.login()){Session session=conn.openSession();打开一个会话session。.

#shell脚本远程登录#shell远程调用脚本命令行#shell脚本远程登录sftp

随机阅读

qrcode
访问手机版