繁体   English   中英

SSH后与虚拟串口通信

[英]communicate to virtual serial port after SSH

我想与服务器的虚拟串行端口通信。 涉及的步骤是。

1.SSH in to iLO 
2.enter vsp command
3.A virtual serial port session is opened 
4.it asks for server credentials and then
it gives us a server terminal experience we can send any
command as we do in a terminal opened in the server itself

所以我的目标是从 java 以任何方式自动执行上述所有步骤。

我已经通过 jsch 完成了前两个步骤,但是一旦它进入虚拟串行端口 session,我就无法通信。 我还尝试使用 expect for linux 自动执行终端命令 in expect 即使我在进入 VSP session 后看到相同的模式我无法通信我尝试过 autoexpect 也没有用 下面是我的 jsch 代码

   public static void main(String[] args) {
    String host="10.10.100.209";
    String user="administrator";
    String password="2xR3M0t3$$";
    String command1="vsp";     
    try{
        
        java.util.Properties config = new java.util.Properties(); 
        config.put("StrictHostKeyChecking", "no");
        JSch jsch = new JSch();
        Session session=jsch.getSession(user, host, 22);
        session.setPassword(password);
        session.setConfig(config);
        session.connect();
        System.out.println("Connected");
        ChannelExec channel = (ChannelExec) session.openChannel("exec");
        InputStream in = channel.getInputStream();
        channel.setCommand("vsp");
        OutputStream out = channel.getOutputStream();
        channel.connect();

  byte[] tmp=new byte[1024];
        
        while(true){
          while(in.available()>0){
            int i=in.read(tmp, 0, 1024);
            if(i<0)break;
            System.out.print("out"+new String(tmp, 0, i));
          
           
            
          }
         
          if(channel.isClosed()){
            System.out.println("exit-status: "+channel.getExitStatus());
            break;
          }
        }
        channel.disconnect();
        

现在我的问题是在我将 ssh 写入 iLO 后如何与虚拟串口通信。

使用 ChannelShell 而不是 ChannelExec。

您的用例似乎是交互式的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM