简体   繁体   English

如何从java连接到远程unix框并在其中运行unix脚本?

[英]How to connect to a remote unix box from java and run unix script in it?

I need help in writing java code that can connect to a remote UNIX box, and run a script on that box. 我需要帮助编写可以连接到远程UNIX盒子的java代码,并在该盒子上运行脚本。 I have scoured the internet, but I have been unable to find proper documentation on how this can be accomplished. 我已经浏览了互联网,但我无法找到有关如何实现这一目标的适当文档。

Where is the best place to start reading about this ? 哪个是开始阅读这个的最好的地方? What all should I know ? 我应该知道什么?

Any help is appreciated. 任何帮助表示赞赏。 Thanks. 谢谢。

ssh is probably the best protocol to use for that sort of thing. ssh可能是用于此类事情的最佳协议。 It's more secure than telnet and can be set to up to use authentication keys so your code won't need to know (or ask the user) for the password to the remote box. 它比telnet更安全,并且可以设置为使用身份验证密钥,因此您的代码不需要知道(或询问用户)远程盒的密码。

Java Secure Channel (JSch) is a popular pure Java implementation of the ssh protocol. Java安全通道(JSch)是ssh协议的流行纯Java实现。

You can use telnet and/or ssh to connect to the box. 您可以使用telnet和/或ssh连接到该框。 Then you can send your command, as you would do it in a terminal. 然后你可以像在终端中那样发送命令。 Look out for a telnet/ssh implementation for java with good documentation. 请注意具有良好文档的java的telnet / ssh实现。 Telnet should be simpler, but there is no encryption. Telnet应该更简单,但没有加密。 Apache has a telnet implementation: http://commons.apache.org/net/ Apache有一个telnet实现: http//commons.apache.org/net/

regards Andreas 问安德烈亚斯

你可以使用Runtime.exec(java.lang.String)

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

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