java连接linux服务器执行shell命令(框架分析+推荐)

一、分类+连接方式

  1. 程序打成jar包,在本地服务器上执行shell命令。这种使用MyRuntimeUtil工具类
  2. java程序远程linux服务器有两个框架分别是:jsch与ganymed-ssh2框架**。**推荐使用jsch框架因为ganymed-ssh2框架不支持麒麟服务器的连接原因是openssl版本过高,ganymed-ssh框架不维护了所以不支持。

二、执行本地的shell命令

    <dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.7.21</version></dependency>

工具类

package com.dameng.util;
import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.text.StrBuilder;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.log.StaticLog;import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
/*** @author xgt(小光头)* @version 1.0* @date 2022-3-3 22:40*/
public class MyRuntimeUtil {/*** 执行系统命令,使用系统默认编码** @param cmds 命令列表,每个元素代表一条命令* @return 执行结果* @throws IORuntimeException IO异常*/public static String execForStr(String... cmds) throws IORuntimeException {return execForStr(CharsetUtil.systemCharset(), cmds);}/*** 执行系统命令,使用系统默认编码** @param charset 编码* @param cmds    命令列表,每个元素代表一条命令* @return 执行结果* @throws IORuntimeException IO异常* @since 3.1.2*/public static String execForStr(Charset charset, String... cmds) throws IORuntimeException {return getResult(exec(cmds), charset);}public static String execForErrStr(Charset charset,String cmd) throws IORuntimeException {return getResultErr(exec(cmd), charset);}/*** 执行系统命令,使用系统默认编码**/public static String execForStr(Charset charset, String cmds) throws IORuntimeException {return getResult(exec(cmds), charset);}/*** 执行系统命令,使用系统默认编码** @param cmds 命令列表,每个元素代表一条命令* @return 执行结果,按行区分* @throws IORuntimeException IO异常*/public static List<String> execForLines(String... cmds) throws IORuntimeException {return execForLines(CharsetUtil.systemCharset(), cmds);}/*** 执行系统命令,使用系统默认编码** @param charset 编码* @param cmds    命令列表,每个元素代表一条命令* @return 执行结果,按行区分* @throws IORuntimeException IO异常* @since 3.1.2*/public static List<String> execForLines(Charset charset, String... cmds) throws IORuntimeException {return getResultLines(exec(cmds), charset);}/*** 执行命令<br>* 命令带参数时参数可作为其中一个参数,也可以将命令和参数组合为一个字符串传入** @param cmds 命令* @return {@link Process}*/public static Process exec(String... cmds) {Process process;try {process = new ProcessBuilder(handleCmds(cmds)).redirectErrorStream(true).start();} catch (IOException e) {throw new IORuntimeException(e);}return process;}/*** 执行命令<br>* 命令带参数时参数可作为其中一个参数,也可以将命令和参数组合为一个字符串传入** @param cmd 命令* @return {@link Process}*/public static Process exec(String cmd) {Process process;try {// 得到Java进程的相关Runtime运行对象Runtime runtime = Runtime.getRuntime();if(cmd.indexOf("|")>0){String[] cmdArr = {"sh","-c",cmd};process = runtime.exec(cmdArr);}else{process = runtime.exec(cmd);}} catch (IOException e) {throw new IORuntimeException(e);}return process;}/*** 执行命令<br>* 命令带参数时参数可作为其中一个参数,也可以将命令和参数组合为一个字符串传入** @param envp 环境变量参数,传入形式为key=value,null表示继承系统环境变量* @param cmds 命令* @return {@link Process}* @since 4.1.6*/public static Process exec(String[] envp, String... cmds) {return exec(envp, null, cmds);}/*** 执行命令<br>* 命令带参数时参数可作为其中一个参数,也可以将命令和参数组合为一个字符串传入** @param envp 环境变量参数,传入形式为key=value,null表示继承系统环境变量* @param dir  执行命令所在目录(用于相对路径命令执行),null表示使用当前进程执行的目录* @param cmds 命令* @return {@link Process}* @since 4.1.6*/public static Process exec(String[] envp, File dir, String... cmds) {try {return Runtime.getRuntime().exec(handleCmds(cmds), envp, dir);} catch (IOException e) {throw new IORuntimeException(e);}}// -------------------------------------------------------------------------------------------------- result/*** 获取命令执行结果,使用系统默认编码,获取后销毁进程** @param process {@link Process} 进程* @return 命令执行结果列表*/public static List<String> getResultLines(Process process) {return getResultLines(process, CharsetUtil.systemCharset());}/*** 获取命令执行结果,使用系统默认编码,获取后销毁进程** @param process {@link Process} 进程* @param charset 编码* @return 命令执行结果列表* @since 3.1.2*/public static List<String> getResultLines(Process process, Charset charset) {InputStream in = null;try {in = process.getInputStream();return IoUtil.readLines(in, charset, new ArrayList<>());} finally {IoUtil.close(in);destroy(process);}}/*** 获取命令执行结果,使用系统默认编码,,获取后销毁进程** @param process {@link Process} 进程* @return 命令执行结果列表* @since 3.1.2*/public static String getResult(Process process) {return getResult(process, CharsetUtil.systemCharset());}/*** 获取命令执行结果,获取后销毁进程** @param process {@link Process} 进程* @param charset 编码* @return 命令执行结果列表* @since 3.1.2*/public static String getResult(Process process, Charset charset) {InputStream in = null;InputStream errorStream = null;try {in = process.getInputStream();errorStream = process.getErrorStream();String errorResult = IoUtil.read(errorStream, charset);if(StrUtil.isNotBlank(errorResult)){StaticLog.warn("Shell command execution error, because {}",errorResult);}return IoUtil.read(in, charset);} finally {IoUtil.close(in);IoUtil.close(errorStream);destroy(process);}}/*** 获取错误的执行结果,获取后销毁进程** @param process {@link Process} 进程* @param charset 编码* @return 命令执行结果列表* @since 3.1.2*/public static String getResultErr(Process process, Charset charset) {InputStream in = null;InputStream errorStream = null;try {in = process.getInputStream();errorStream = process.getErrorStream();// System.out.println("252"+IoUtil.read(errorStream, charset));return IoUtil.read(errorStream, charset);} finally {IoUtil.close(in);IoUtil.close(errorStream);destroy(process);}}/*** 获取命令执行异常结果,使用系统默认编码,,获取后销毁进程** @param process {@link Process} 进程* @return 命令执行结果列表* @since 4.1.21*/public static String getErrorResult(Process process) {return getErrorResult(process, CharsetUtil.systemCharset());}/*** 获取命令执行异常结果,获取后销毁进程** @param process {@link Process} 进程* @param charset 编码* @return 命令执行结果列表* @since 4.1.21*/public static String getErrorResult(Process process, Charset charset) {InputStream in = null;try {in = process.getErrorStream();return IoUtil.read(in, charset);} finally {IoUtil.close(in);destroy(process);}}/*** 销毁进程** @param process 进程* @since 3.1.2*/public static void destroy(Process process) {if (null != process) {process.destroy();}}/*** 增加一个JVM关闭后的钩子,用于在JVM关闭时执行某些操作** @param hook 钩子* @since 4.0.5*/public static void addShutdownHook(Runnable hook) {Runtime.getRuntime().addShutdownHook((hook instanceof Thread) ? (Thread) hook : new Thread(hook));}/*** 获得JVM可用的处理器数量(一般为CPU核心数)** @return 可用的处理器数量* @since 5.3.0*/public static int getProcessorCount() {return Runtime.getRuntime().availableProcessors();}/*** 获得JVM中剩余的内存数,单位byte** @return JVM中剩余的内存数,单位byte* @since 5.3.0*/public static long getFreeMemory() {return Runtime.getRuntime().freeMemory();}/*** 获得JVM已经从系统中获取到的总共的内存数,单位byte** @return JVM中剩余的内存数,单位byte* @since 5.3.0*/public static long getTotalMemory() {return Runtime.getRuntime().totalMemory();}/*** 获得JVM中可以从系统中获取的最大的内存数,单位byte,以-Xmx参数为准** @return JVM中剩余的内存数,单位byte* @since 5.3.0*/public static long getMaxMemory() {return Runtime.getRuntime().maxMemory();}/*** 获得JVM最大可用内存,计算方法为:<br>* 最大内存-总内存+剩余内存** @return 最大可用内存*/public static long getUsableMemory() {return getMaxMemory() - getTotalMemory() + getFreeMemory();}/*** 获取当前进程ID,首先获取进程名称,读取@前的ID值,如果不存在,则读取进程名的hash值** @return 进程ID* @throws UtilException 进程名称为空* @since 5.7.3*/public static int getPid() throws UtilException {final String processName = ManagementFactory.getRuntimeMXBean().getName();if (StrUtil.isBlank(processName)) {throw new UtilException("Process name is blank!");}final int atIndex = processName.indexOf('@');if (atIndex > 0) {return Integer.parseInt(processName.substring(0, atIndex));} else {return processName.hashCode();}}/*** 处理命令,多行命令原样返回,单行命令拆分处理** @param cmds 命令* @return 处理后的命令*/private static String[] handleCmds(String... cmds) {if (ArrayUtil.isEmpty(cmds)) {throw new NullPointerException("Command is empty !");}// 单条命令的情况if (1 == cmds.length) {final String cmd = cmds[0];if (StrUtil.isBlank(cmd)) {throw new NullPointerException("Command is blank !");}cmds = cmdSplit(cmd);}return cmds;}/*** 命令分割,使用空格分割,考虑双引号和单引号的情况** @param cmd 命令,如 git commit -m 'test commit'* @return 分割后的命令*/private static String[] cmdSplit(String cmd) {final List<String> cmds = new ArrayList<>();final int length = cmd.length();final Stack<Character> stack = new Stack<>();boolean inWrap = false;final StrBuilder cache = StrUtil.strBuilder();char c;for (int i = 0; i < length; i++) {c = cmd.charAt(i);switch (c) {case CharUtil.SINGLE_QUOTE:case CharUtil.DOUBLE_QUOTES:if (inWrap) {if (c == stack.peek()) {//结束包装stack.pop();inWrap = false;}cache.append(c);} else {stack.push(c);cache.append(c);inWrap = true;}break;case CharUtil.SPACE:if (inWrap) {// 处于包装内cache.append(c);} else {cmds.add(cache.toString());cache.reset();}break;default:cache.append(c);break;}}if (cache.hasContent()) {cmds.add(cache.toString());}return cmds.toArray(new String[0]);}
}

使用方法

package java.nio.charset;Charset charset = Charset.forName("UTF-8");
MyRuntimeUtil.execForStr(charset,"ls");

三、Jsch远程连接执行

      <dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.7.21</version></dependency><!-- jsch的方式 远程连接的包--><dependency><groupId>com.jcraft</groupId><artifactId>jsch</artifactId><version>0.1.55</version></dependency>

工具类

package com.dameng.util;import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.ssh.JschRuntimeException;
import com.jcraft.jsch.*;import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Properties;/*** 执行Shell工具类*/
public class ExecuteShellUtil {/** 未调用初始化方法 错误提示信息 */private static final String DONOT_INIT_ERROR_MSG = "please invoke init(...) first!";private static Session session;private ExecuteShellUtil() {}/*** 获取ExecuteShellUtil类实例对象** @return 实例* @date 2019/4/29 16:58*/public static ExecuteShellUtil getInstance() {return new ExecuteShellUtil();}/*** 初始化** @param ip*         远程Linux地址* @param port*         端口* @param username*         用户名* @param password*         密码* @throws JSchException*         JSch异常* @date 2019/3/15 12:41*/public void init(String ip, Integer port, String username, String password) throws JSchException {JSch jsch = new JSch();jsch.getSession(username, ip, port);session = jsch.getSession(username, ip, port);session.setPassword(password);Properties sshConfig = new Properties();sshConfig.put("StrictHostKeyChecking", "no");session.setConfig(sshConfig);session.connect(1200 * 1000);}/*** 执行一条命令*/public String execCmd(String command) throws Exception {//        if (session == null || channel == null || channelExec == null) {//            throw new Exception(DONOT_INIT_ERROR_MSG);
//        }// 打开执行shell指令的通道Channel channel = session.openChannel("exec");ChannelExec channelExec = (ChannelExec) channel;channelExec.setCommand("source /etc/profile && source ~/.bash_profile && source ~/.bashrc &&  adb devices");channelExec.setCommand(command);channel.setInputStream(null);channelExec.setErrStream(System.err);// channel.setXForwarding();channel.connect();StringBuilder sb = new StringBuilder(16);try (InputStream in = channelExec.getInputStream();InputStreamReader isr = new InputStreamReader(in, StandardCharsets.UTF_8);BufferedReader reader = new BufferedReader(isr)) {String buffer;while ((buffer = reader.readLine()) != null) {sb.append("\n").append(buffer);}return sb.toString();}finally {if (channelExec != null && channelExec.isConnected()) {channelExec.disconnect();}if ( channel != null && channel.isConnected()) {channel.disconnect();}}}/*** 执行一条命令 获取错误流中的内容*/public String execCmdErrContent(String command) throws Exception {//        if (session == null || channel == null || channelExec == null) {//            throw new Exception(DONOT_INIT_ERROR_MSG);
//        }// 打开执行shell指令的通道Channel channel = session.openChannel("exec");ChannelExec channelExec = (ChannelExec) channel;channelExec.setCommand(command);channel.setInputStream(null);ByteArrayOutputStream err  = new ByteArrayOutputStream();channelExec.setErrStream(err);channel.connect();StringBuilder sb = new StringBuilder(16);try (InputStream in = channelExec.getErrStream();InputStreamReader isr = new InputStreamReader(in, StandardCharsets.UTF_8);BufferedReader reader = new BufferedReader(isr)) {String buffer;while ((buffer = reader.readLine()) != null) {sb.append("\n").append(buffer);}if(StrUtil.contains(sb.toString(), "没有那个文件或目录")){return "";}else{return sb.toString();}}finally {if (channelExec != null && channelExec.isConnected()) {channelExec.disconnect();}if ( channel != null && channel.isConnected()) {channel.disconnect();}}}public static void closeConnect() {if (session != null && session.isConnected()) {session.disconnect();}}
}

使用方法

package com.dameng;import cn.hutool.core.text.StrSplitter;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.ssh.JschUtil;
import com.dameng.util.ExecuteShellUtil;
import com.dameng.util.ShellCmdUtil;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import org.junit.Test;import java.math.BigDecimal;
import java.util.List;/*** Unit test for simple App.*/
public class JschUtilTest
{/*** Jsch方式4830*/@Testpublic void shouldAnswerWithTrue() {long currentTimeMillis = System.currentTimeMillis();ExecuteShellUtil instance = ExecuteShellUtil.getInstance();try {//instance.init("192.168.60.179", 22, "root","password123.1");//  String ls = instance.execCmd("top -p 21475 -n 1 -b");String ls = instance.execCmd("cat /opt/dmdbms/log/dm_DW1_01B_202203.log | grep -v 'INFO'");List<String> lineFreedList = StrSplitter.splitByRegex(StrUtil.trimToEmpty(ls), "\n", -1, true, true);for (String s : lineFreedList) {List<String> stringList = StrSplitter.split(StrUtil.trimToEmpty(s), "=", -1, true, true);System.out.println(stringList);}System.out.println(ls);//
//            // 计算内存使用率(已使用内存/总内存)
//            String freeStr = instance.execCmd("free | sed -n '2p'");
//            List<String> freeInfoList = StrSplitter.splitByRegex(StrUtil.trimToEmpty(freeStr), "\\s+", -1, true, true);
//            String allMemory = freeInfoList.get(1);
//            String usedMemory = freeInfoList.get(2);
//            double f1 = new BigDecimal(Float.valueOf(usedMemory) / Float.valueOf(allMemory)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() * 100;
//
//
//
//
//            System.out.println(ls);
//            long currentTimeMillis1 = System.currentTimeMillis();
//            System.out.println("Jsch方式"+(currentTimeMillis1-currentTimeMillis));} catch (Exception e) {System.out.println("error info");e.printStackTrace();}}
}

四、ganymed-ssh2远程连接执行

    <dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.7.21</version></dependency><!-- GanymedUtil的方式 远程连接的包--><dependency><groupId>ch.ethz.ganymed</groupId><artifactId>ganymed-ssh2</artifactId><version>262</version></dependency>

工具类

package com.dameng.util;import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.ConnectionInfo;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.log.StaticLog;
import com.dameng.core.exception.MyGanymedException;
import com.dameng.core.exception.MyHostConnectException;
import com.dameng.core.exception.MyResolutionException;
import com.dameng.domain.OsInfo;import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.List;/*** @author xgt(小光头)* @version 1.0* @date 2022-2-26 15:36*/
public class MyGanymedSingleUtil {private MyGanymedSingleUtil() {}private static Connection connect;private static  MyGanymedSingleUtil myGanymedSingleUtil;public static MyGanymedSingleUtil getInstance() {if(myGanymedSingleUtil == null){myGanymedSingleUtil =new MyGanymedSingleUtil();}return myGanymedSingleUtil;}/*** 连接到服务器* @param sshHost 主机* @param sshPort 端口* @return {@link Connection}*/public  Connection connect(String sshHost, int sshPort) {connect = new Connection(sshHost, sshPort);try {connect.connect();} catch (IOException e) {throw new IORuntimeException(e);}return connect;}/*** 打开远程会话** @param sshHost 主机* @param sshPort 端口* @param sshUser 用户名,如果为null,默认root* @param sshPass 密码* @return {@link Session}*/public void openConnect(String sshHost, int sshPort, String sshUser, String sshPass) throws MyHostConnectException {// 默认root用户if (StrUtil.isEmpty(sshUser)) {sshUser = "root";}connect = connect(sshHost, sshPort);try {connect.authenticateWithPassword(sshUser, sshPass);ConnectionInfo connectionInfo = connect.getConnectionInfo();// session = connect.openSession();} catch (IOException e) {throw new MyHostConnectException(e);}}/*** 执行Shell命令(使用EXEC方式)* <p>* 此方法单次发送一个命令到服务端,不读取环境变量,执行结束后自动关闭Session,不会产生阻塞。* </p>** @param cmd       命令* @param charset   发送和读取内容的编码* @return 执行返回结果*/public  String exec(String cmd, String charset) throws Exception {final String result;final String stderrStr;ByteArrayOutputStream errStream = new ByteArrayOutputStream();Session session = null;try {session = connect.openSession();Charset charset1 = Charset.forName(charset);session.execCommand(cmd, charset1.name());result = IoUtil.read(new StreamGobbler(session.getStdout()), charset1);//打印错误的流输出IoUtil.copy(new StreamGobbler(session.getStderr()), errStream);stderrStr = new String(errStream.toByteArray(),charset);} finally {session.close();}if(!StrUtil.isEmpty(stderrStr)){throw new MyGanymedException(stderrStr);}return result;}/*** 执行Shell命令* <p>* 此方法单次发送一个命令到服务端,自动读取环境变量,执行结束后自动关闭Session,不会产生阻塞。* </p>** @param cmd       命令* @param charset   发送和读取内容的编码* @param errStream 错误信息输出到的位置* @return 执行返回结果*/public  String execByShell(String cmd, Charset charset, OutputStream errStream) {final String result;Session session = null;try {//这个方法有问题session.requestDumbPTY();IoUtil.write(session.getStdin(), charset, true, cmd);result = IoUtil.read(new StreamGobbler(session.getStdout()), charset);if(null != errStream){// 错误输出IoUtil.copy(new StreamGobbler(session.getStdout()), errStream);}} catch (IOException e) {throw new IORuntimeException(e);} finally {close(session);}return result;}/*** 关闭会话**/public  void close(Session session) {if(session!=null){session.close();}}/*** 关闭会话**/public  void closeConnect() {if(connect!=null){connect.close();}}}

使用方式

package com.dameng;import ch.ethz.ssh2.Session;
import cn.hutool.extra.ssh.GanymedUtil;
import cn.hutool.extra.ssh.JschUtil;
import com.dameng.util.ExecuteShellUtil;
import com.dameng.util.MyGanymedUtil;
import org.junit.Test;import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;/*** Unit test for simple App.*/
public class GanymedUtilTest
{private static String DEFAULTCHART = "UTF-8";/*** Rigorous Test :-)*/@Testpublic void shouldAnswerWithTrue()  {long currentTimeMillis = System.currentTimeMillis();//  Session session = JschUtil.getSession("192.168.60.177", 22, "root", "root");Session session = MyGanymedUtil.openSession("192.168.60.177", 22, "root", "root");ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();Charset charset = Charset.forName("UTF-8");String ls = MyGanymedUtil.exec(session, "awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \\t]*//;s/[ \\t]*$//'", charset, byteArrayOutputStream);String str = new String(byteArrayOutputStream.toByteArray(),charset);System.out.println(ls);System.out.println("error="+str);long currentTimeMillis1 = System.currentTimeMillis();System.out.println("Ganymed方式"+(currentTimeMillis1-currentTimeMillis));}
}

问题总结

1. dd命令进行磁盘测速方法获取不到值

经过分析发现执行结果都在工具类的错误流中,并非在正常流中,自己打印一下错误流就发现了。

  1. 本地的shell命令的话参考一下工具类的MyRuntimeUtil.execForErrStr(charset,cmd)这个方法。
  2. jsch框架的话参考一下工具类的jschInstance.execCmdErrContent(cmd)这个方法。

2. 执行ll命令报错

采用框架中的方法调用,是不带用户的环境变量的所以ll命令会报错,ll命令是ls -l命令封装后的结果。所以需要使用ls -l命令。

3.执行top命令报错

不支持top这种不断刷新交互式的命令。加参数获取一次性结果。

top -b -n 1 |head -n 4 | grep 'sy' | grep 'us' | awk '{print $2}'

java连接linux服务器执行shell命令(框架分析+推荐)相关推荐

  1. JSch连接不上Linux服务器,windows 下 java程序jsch连接远程linux服务器执行shell命令

    java远程连接服务的shell需要使用SSH的登录方式,可以使用JSch技术.JSch 是SSH2的一个纯Java实现.它允许你连接到一个sshd 服务器,使用端口转发,X11转发,文件传输等等. ...

  2. java 远程shell脚本_java通过ssh连接服务器执行shell命令详解及实例

    java通过ssh连接服务器执行shell命令详解 java通过ssh连接服务器执行shell命令:JSch 是SSH2的一个纯Java实现.它允许你连接到一个sshd 服务器,使用端口转发,X11转 ...

  3. java ganymed ssh2_java 远程执行Shell命令-通过ganymed-ssh2连接

    一.实现远程执行 此程序的目的是执行远程机器上的Shell脚本. [环境参数] 远程机器IP:192.168.243.21 用户名:user 密码:password 命令:python /data/a ...

  4. python连接linux服务器并使用命令_python基于paramiko模块实现远程连接Linux虚拟机(服务器)并执行指定命令返回输出结果...

    对于开发者来说,windows是我们接触最多的操作系统了,但是Linux是我们必不可少的一项重要技能,很多服务或者应用都需要在Linux下运行,掌握Linux系统的基本使用也是非常重要的,今天有一个需 ...

  5. Java连接Linux服务器上传文件

    背景: 项目中有需求要使用Java上传文件至服务器及执行某些shell脚本.通过查阅一些资料,反复测试了两套方案,各有优缺点,下面分别阐述一下. 实现方案一:SpringBoot + JSch + L ...

  6. linux c 执行shell命令并获取返回结果

    最近在项目中用到了C语言执行shell命令的问题,调查了一下,一般有system函数.exec族函数,但是还不太清楚怎么获取shell命令执行的返回信息. 例如执行一个ifconfig命令,肯定需要获 ...

  7. java 连接Linux服务器并执行指令

    直接上代码. /*** Created by hpp on 2017/6/5.*/import ch.ethz.ssh2.Connection; import ch.ethz.ssh2.Session ...

  8. java使用ganymed-ssh2远程执行shell命令

    先上依赖 <!-- https://mvnrepository.com/artifact/ch.ethz.ganymed/ganymed-ssh2 --> <dependency&g ...

  9. linux远程执行shell命令行,linux shell 远程执行命令--ftp

    linux shell 远程执行命令--ftp 2018-12-07 ftp有很多命令,熟悉这些命令你能大大的提高工作效率: FTP命令行格式为: ftp -v -d -i -n -g [主机名] , ...

最新文章

  1. Windows IIS7 下安装配置 PHP7.0
  2. 170828、Eclipse Java注释模板设置详解以及版权声明
  3. 解决Git中fatal: refusing to merge unrelated histories(亲测)
  4. LeetCode 109. 有序链表转换二叉搜索树(快慢指针+递归)
  5. js for in 获得遍历数组索引和对象属性
  6. DEDE的简略标题标签的使用问题
  7. Spring Boot的自动装配原理
  8. 2020-06-21
  9. C# WinForm界面设计教程
  10. python写入文件报错解决方法
  11. SW小技巧2:将属性链接到 SOLIDWORKS 工程图的简便方法
  12. 数据分析实战项目练习——物流行业数据分析
  13. SSAS Tabular
  14. 网站搭建需要什么技术?
  15. 美颜sdk中,实现人脸识别的主要方法有哪些?
  16. consume(consume名词)
  17. 型号不同的计算机内存条可以通用么,笔记本内存条和台式机通用吗
  18. 智慧军营部队车辆管理系统软件
  19. 12.看板方法——度量和管理报告笔记
  20. 为什么航班停在远机位?

热门文章

  1. python打印字节流_Python 调用系统命令的模块 Subprocess
  2. java文件下载并添加水印_Java下载文件加文字水印(Excel、PDF、图片)
  3. V8 Promise源码全面解读
  4. egret.Shape渲染集合图形
  5. 51 Nod 1509 加长棒(巧妙的隔板法计数)
  6. 远程服务器存储之JDK方式
  7. 设置DataGrid自动生成列的宽度
  8. [Python从零到壹] 十一.数据分析之Numpy、Pandas、Matplotlib和Sklearn入门知识万字详解(1)
  9. [Python人工智能] 三.TensorFlow基础之Session、变量、传入值和激励函数
  10. PyTorch 加载超大 Libsvm 格式数据