Compare commits
1 Commits
master
...
jsx_231016
| Author | SHA1 | Date |
|---|---|---|
|
|
da0a794c48 |
|
|
@ -10,6 +10,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.jcraft.jsch.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -18,10 +19,6 @@ import org.springframework.web.socket.TextMessage;
|
|||
import org.springframework.web.socket.WebSocketSession;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jcraft.jsch.ChannelShell;
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.Session;
|
||||
import com.jcraft.jsch.UserInfo;
|
||||
|
||||
import net.educoder.bridge.webssh.model.ConnectInfo;
|
||||
import net.educoder.bridge.webssh.model.WebscoketObj;
|
||||
|
|
@ -174,6 +171,10 @@ public class JchService {
|
|||
session.setServerAliveInterval(30 * 1000); // 30秒心跳一次,用于保活
|
||||
|
||||
session.connect();
|
||||
|
||||
//本次ssh导入环境变量。
|
||||
executeCommend(session, "export $(cat /proc/1/environ |tr '\0' '\n' |grep -v ' ' | xargs)");
|
||||
|
||||
ChannelShell channel = (ChannelShell) session.openChannel("shell");
|
||||
channel.setPtyType("xterm");
|
||||
|
||||
|
|
@ -310,4 +311,15 @@ public class JchService {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void executeCommend(Session session, String cmd){
|
||||
try {
|
||||
ChannelExec channelExec = (ChannelExec) session.openChannel("exec");
|
||||
channelExec.setCommand(cmd);
|
||||
channelExec.connect();
|
||||
|
||||
// 关闭ChannelExec
|
||||
channelExec.disconnect();
|
||||
}catch (Exception ignore){}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue