通过使用远程SHELL执行框架 sshxcute 实现远程登录Linux并执行命令。
sshxcute 项目地址:
http://code.google.com/p/sshxcute/
示例代码:
import net.neoremind.sshxcute.core.ConnBean; import net.neoremind.sshxcute.core.Result; import net.neoremind.sshxcute.core.SSHExec; import net.neoremind.sshxcute.task.CustomTask; import net.neoremind.sshxcute.task.impl.ExecCommand; public class ConnectWithSSH { public static void main(String[] args) { ConnBean cb = new ConnBean("ip", "username", "password"); CustomTask ct1 = new ExecCommand("ls -l /opt/"); SSHExec ssh = null; try { ssh = SSHExec.getInstance(cb); ssh.connect(); Result res = ssh.exec(ct1); if (res.isSuccess) { System.out.println("Return code: " + res.rc); System.out.println("sysout: " + res.sysout); } else { System.out.println("Return code: " + res.rc); System.out.println("error message: " + res.error_msg); } } catch (Exception e) { e.printStackTrace(); } finally { ssh.disconnect(); } } }
sshxcute 类结构:
相关推荐
java连接linux,执行shell命令的工具类 sshxcute.jar
sshxcute 就是这样一个框架工具集,它基于 JSCH 构建,允许工程师利用Java 代码通过 SSH 连接远程批量执行 Linux/UNIX 系统上的命令或者脚本,同时加入了判断成功与否,取回输出等多种实用功能。sshxcute 不管是针对...
通过java连接linux,每次打开通道以后执行一次命令.
本地cmd命令, 输入命令, 并在控制台输出命令执行结果 jsch 远程ssh到linux服务器, 执行结果并显示输出
java通过ssh调用centos7指令,获取磁盘空间使用率、磁盘空间使用情况、网络使用情况,CPU使用率,内存使用率
NULL 博文链接:https://zrzdemon.iteye.com/blog/1499804
ant运行scp以及sshexec任务所必须的jar包,这是optional的,所以ant默认不会有的,需要自己加上
java操作Linux-shell命令的jar文件,java语言执行 Linux-cmd命令 java操作Linux-shell命令的jar文件,java语言执行 Linux-cmd命令 java操作Linux-shell命令的jar文件,java语言执行 Linux-cmd命令 java操作Linux-shell...
http://www.ganymed.ethz.ch/ssh2/在这个网址下载一个调用ssh和scp命令的jar包。 然后,就可以写程序了。将上面的jar包导入MyEclipse,附一个类的实例代码。
Jsch远程操作linux命令Demo: Jsch远程操作linux命令Demo :Exec2.java 通过jsch 实现远程执行Linux命令(命令参数支持中文); Shell.java 实现与Linux交互对话通讯(支持中文)。
java操作Linux环境,jsch,执行Linux命令;执行SSH上传文件;执行远程脚本
基于sshConnect的linux服务器的shell命令调用,并获取命令返回结果的实例。亲测有效!
java远程访问linux服务器操作 远程执行shll脚本或者命令、上传下载文件 package com.szkingdom.kfit.bank.ccbDirectShortcut.helper; import ch.ethz.ssh2.Connection; import ch.ethz.ssh2.SCPClient; import ...
通过linux的SSH端口使用java代码远程对指定的linux服务器上执行shell命令,实测有用
纯java实现的ssh协议(jsch),支持同时连接多台linux主机,执行相同的命令。只需配置目标主机的ip地址、用户名和密码即可实现远程操作。服务器无需配置ssh对等协议或安装任何agent插件。并发远程主机主机连接,顺序...
Ganymed SSH-2 for Java是用纯Java实现SSH-2协议的一个包。可以利用它直接在Java程序中连接SSH服务器,执行linux命令
Java 代码通过 SSH 连接远程批量执行 Linux/UNIX 系统上的命令或者脚本,同时加入了判断成功与否,取回输出等多种 实用功能。 文档参考 https://www.ibm.com/developerworks/cn/opensource/os-sshxcute/
ssh-helperssh助手,可以很方便的在开发工具内部快捷的通过ssh登录远程linux服务器,并执行任何linux命令使用时,只需简单修改server.xml,将可能用到的linux服务器信息配置进来,然后运行Main即可
每次开机自动启动的java进程,页面上的关机按钮都无法实现关机功能,但是此时如果以chb账号通过ssh登录该服务器,手动杀掉tomcat进程,然后再重新启动tomcat,页面上的关机按钮就有效了
Java 在用 ssh 协议远程在 linux 目标主机上执行命令的架包