java代码执行shell命令

java代码执行shell命令,需要通过google出品的工具类ssxcute.jar,下载地址:

https://download.csdn.net/download/qq_15076569/10797217

java代码操作shell代码:


import net.neoremind.sshxcute.core.ConnBean;
import net.neoremind.sshxcute.core.SSHExec;
import net.neoremind.sshxcute.exception.TaskExecFailException;
import net.neoremind.sshxcute.task.impl.ExecCommand;

/**
 * java执行shell命令
 */
public class excuteShell {

    public static void main(String[] args) throws TaskExecFailException {
        //连接linux配置
        ConnBean connBean = new ConnBean("192.168.254.100", "root", "123456");
        //SSH连接对象
        SSHExec instance = SSHExec.getInstance(connBean);
        //打开连接
        instance.connect();
        //指定语句对象,参数为可变参数
        ExecCommand execCommand = new ExecCommand("echo 'hello world'");
        //执行对象
        instance.exec(execCommand);
        //关闭连接
        instance.disconnect();
    }

}

猜你喜欢

转载自blog.csdn.net/qq_15076569/article/details/84311026
今日推荐