ssh登陆后,执行命令不能返回结果,且 getExitStatus 返回为1
情况这样的 我直接用此程序登陆LINUX 系统是没问题的,可以将命令的执行结果返回,且 sess.getExitStatus 的返回是0 正常
但我用此程序登陆 一个设备,操作系统是 Welcome to MontaVista Linux 3.0, Professional Edition
无论执行什么命令都返回下面这样的欢迎信息,不知道是为什么?
而且 sess.getExitStatus 的返回是1
cli 2.1.2
Login from 221.10.44.138 port:22
Press TAB anytime, CLI will help you to finish the command line,
or gives the available keywords.
If you firstly use CLI, you can try "get" command.
For example:
set wlan o(press TAB)
you will get the following:
set wlan operationmode
and press TAB again to see what you will get!
找了一个程序,但每次都返回的是欢迎信息,并没将“get system cpu usage” 结果返回到系统,请高手帮忙分析下。
程序代码:
try
{
/* Create a connection instance */
Connection conn = new Connection(hostname);
/* Now connect */
conn.connect();
/* Authenticate.
* If you get an IOException saying something like
* "Authentication method password not supported by the server at this stage."
* then please check the FAQ.
*/
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false)
throw new IOException("Authentication failed.");
/* Create a session */
Session sess = conn.openSession();
sess.execCommand("get system cpu usage");
System.out.println("Here is some information about the remote host:");
/*
* This basic example does not handle stderr, which is sometimes dangerous
* (please read the FAQ).
*/
InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true)
{
String line = br.readLine();
if (line == null)
break;
System.out.println(line);
}
/* Show exit status, if available (otherwise "null") */
System.out.println("ExitCode: " + sess.getExitStatus());
/* Close this session */
sess.close();
/* Close the connection */
conn.close();
}
catch (IOException e)
{
e.printStackTrace(System.err);
System.exit(2);
}
但我用此程序登陆 一个设备,操作系统是 Welcome to MontaVista Linux 3.0, Professional Edition
无论执行什么命令都返回下面这样的欢迎信息,不知道是为什么?
而且 sess.getExitStatus 的返回是1
cli 2.1.2
Login from 221.10.44.138 port:22
Press TAB anytime, CLI will help you to finish the command line,
or gives the available keywords.
If you firstly use CLI, you can try "get" command.
For example:
set wlan o(press TAB)
you will get the following:
set wlan operationmode
and press TAB again to see what you will get!
找了一个程序,但每次都返回的是欢迎信息,并没将“get system cpu usage” 结果返回到系统,请高手帮忙分析下。
程序代码:
try
{
/* Create a connection instance */
Connection conn = new Connection(hostname);
/* Now connect */
conn.connect();
/* Authenticate.
* If you get an IOException saying something like
* "Authentication method password not supported by the server at this stage."
* then please check the FAQ.
*/
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false)
throw new IOException("Authentication failed.");
/* Create a session */
Session sess = conn.openSession();
sess.execCommand("get system cpu usage");
System.out.println("Here is some information about the remote host:");
/*
* This basic example does not handle stderr, which is sometimes dangerous
* (please read the FAQ).
*/
InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true)
{
String line = br.readLine();
if (line == null)
break;
System.out.println(line);
}
/* Show exit status, if available (otherwise "null") */
System.out.println("ExitCode: " + sess.getExitStatus());
/* Close this session */
sess.close();
/* Close the connection */
conn.close();
}
catch (IOException e)
{
e.printStackTrace(System.err);
System.exit(2);
}
...全文
相关推荐
Python实现SSH远程登陆,并执行命令的方法(分享)
下面小编就为大家带来一篇Python实现SSH远程登陆,并执行命令的方法(分享)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Linux下限制SSH登陆以及密码策略
教你如何限制使用SSH登陆操作系统,以及密码策略的安全设置!
关于ssh无法登陆服务器的总结
由ssh无法登陆排查原因,总结的io以及cpu负载过高时的排查命令
虚拟机VMware下centos配置SSH免密码登陆
VMware中建立centos系统,两个centos系统实现免密码登陆,源码截图,亲自实现。
telnet和ssh登陆验证
telnet和ssh登陆验证


