ExecCommand命令失败,当我尝试运行" show version"在dell force10开关上执行命令

时间:2015-03-02 06:44:32

标签: java

我是新来的" sshxcute" api我有一个要求,我想获取我们数据中心的一些交换机的bios版本。

像戴尔力量,博科,思科等。

对于其他交换机,我可以运行命令获取详细信息,但事情不适用于dell force switch我得到" [用法,用法,未找到,失败,失败,错误,错误,异常,异常,而不是有效的]"在检查sampleTask变量时,基本上这个命令失败....

请帮助/建议!!!这是代码片段: -

import net.neoremind.sshxcute.core.ConnBean;
import net.neoremind.sshxcute.core.SSHExec;
import net.neoremind.sshxcute.exception.TaskExecFailException;
import net.neoremind.sshxcute.task.CustomTask;
import net.neoremind.sshxcute.task.impl.ExecCommand;
  public class DemoSwitchLogin {
    public static void main(String args[]){

    //String output = executeCommandOnSwitch("A.B.C.D", "user","password", "/fabos/link_bin/version"); 
    //String output = executeCommandOnSwitch("A.B.C.D", "user","password", "show version | grep BIOS"); 
    String output = executeCommandOnSwitch("A.B.C.D", "user","password", "show version");
    System.out.println("Command output is ::::"+output);


    // Brocade bios Version command : /fabos/link_bin/version
    // Dell Force 10 bios version :  show version
    // Cisco Bios Version ::: show version | grep BIOS

}

public static String executeCommandOnSwitch(String ip, String userName, String password, String command) {
    SSHExec ssh = null;
    String commandResult = null; 
    try {
            ConnBean cb = new ConnBean(ip,userName,password);
            ssh = SSHExec.getInstance(cb);          
            ssh.connect();

            CustomTask sampleTask = new ExecCommand(command);
            net.neoremind.sshxcute.core.Result res = ssh.exec(sampleTask);
            if (res.isSuccess)
            {

                commandResult = res.sysout;
                System.out.println("Command Result:::"+commandResult);
            }
            else
            {

                commandResult = res.error_msg;
            }
    } catch (TaskExecFailException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
    } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
    } finally {
            ssh.disconnect();       
    }
     return commandResult ;
}
  }

注意:我使用的是真正的ips和user / passwd而不是" A.B.C.D","用户","密码"正如这里提到的那样......

谢谢。

0 个答案:

没有答案