Reputation: 85
I want to write a program which connects to remote machines via ssh and install predefined software. Also I wanna make process of installing clear for users by make all it visible to users. I have faced some problems: how to open terminal from java and send commands to it?(OutputStream doesn't work) How to execute command in this terminal when I already ssh? I want to run local scripts on the remote machine and allow user? to interact with terminal, when script is running (for example accept licence of software and so on).
I was trying something like this but it is not working.
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("x-terminal-emulator -e ./script.sh");
Upvotes: 1
Views: 1202
Reputation: 1052
In theory it is possible. You'll need a java library, such as JSch, to interact directly with a terminal via ssh, and then make use of the screen
utility to share a single terminal screen between your java prog and a user.
From your java prog:
screen -d -m -S shared
screen -rx shared
<type your installation commands>
From the remote user:
screen -rx shared
Of course the remote user must wait until the java prog initializes the screen in order to attach to it.
Please note that all kinds of things can go wrong when you let users interact with the screen. Your program must be smart enough to handle it.
Upvotes: 1