如何从远程计算机运行 shell 脚本?
我再次遇到了严重的问题..请帮助我。
我必须更改基于 Linux 的服务器的日期和时间。但该服务器是远程服务器。意味着我必须创建一个应用程序来更改服务器的时间,但该应用程序将在单独的服务器上运行。我正在用java开发我的代码,所以我必须用java程序来实现它,请帮助我。并告诉我如何解决这个问题。如果可能的话给我代码规范。如果可以通过执行 ssh 那么请告诉我如何使用 java 程序创建 ssh。我给出的场景是java程序应该在机器A上运行,并且我必须更改机器B的服务器日期时间。
Again I am in a serious problem .. please help me out.
I have to change a date and time of a server which is linux based . But that server is a remote server . Means I have to make an application which will change the time of the server , but that application will run on separate server. I am developing my code in java so I have to implement it with a java program please help me out. and tell me how to solve this problem. If possible give me the code spec. If it is possible by doing ssh then please tell me how to create ssh using a java program. I am giving the scenario the java program should run on machine A and i have to change the server date time of machine B.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 Java 程序不必这样做。但是,如果必须这样做,您可以通过 SSH 在远程服务器上执行命令。
有多个 Java 库可让您编写通过 SSH 运行命令的程序。此类库之一是:
http://www.cleondris.ch/opensource/ssh2/
Java此库的示例:
http://www.informit.com/指南/content.aspx?g=java&seqNum=489
Your Java program should not have to do that. However if it must be done, you can execute commands on a remote server via SSH.
There are multiple libraries for Java that would let you write programs that run commands via SSH. One such library is:
http://www.cleondris.ch/opensource/ssh2/
Java Example with this library:
http://www.informit.com/guides/content.aspx?g=java&seqNum=489
这个问题的答案:“如何设置远程计算机的日期时间?”(据我所知,您的问题)。
不一定是必须用三层java堆栈来解决的问题。如果您有机器的 ssh 帐户,只需登录并运行
date
:只需将 ssh 放在前面,即可从您的本地 shell 运行远程命令,例如:
An answer to this question: "How do I set the datetime of a remote machine?" (your question, as I understood it).
Not necessarily a problem which must be solved with a three-tier java stack. If you have an ssh account for the machine, just log in and run
date
:You can run remote commands from your local shell by simply putting ssh in the front, e.g.: