Is it possible to run command line on a remote machine (not on the server machine where the application is hosted).
I understand Runtime.getRuntime().exec(".."); will try to run the script on the server machine. Is my understanding correct and is there a way to achieve what I need?
Runtime.getRuntime().exec launches a process on the local machine, not a remote one. Wether that process represents a command line interface or not will be determined by the executable that's run, and the underlying platform.
In order to invoke processes on remote machines you need to:
Invoke a remoting type command, like rsh or ssh
Utilize a remoting third party library, like Jsch
Related
I have aws ec2 instance, i need to connect to ec2 and create script and run the script in ec2 using java,can any one help me.
thanks in advance.
In order to connect to ec2 instance you can use ssh.
If ec2 instance is in private subnet you will have to connect to it using bastion instance, otherwise you can connect directly using public ip address.
After you connected using ssh you can write whatewer script you want, or just copy it directly using scp.
In order to run java program make sure java is installed in your instance (run java -version command). If it is not installed you will have to install jvm first. The commands will be different depending on OS of your instance. Most probably it should be CentOS or Ubuntu.
After java is installed use java -jar jarfilename.jar command to run your application.
Till now I was able to launch multiple EC2 Windows instance & get its parameters (password / IP) with aws-api-tool .
Now I'd like to find a way to execute the selenium grid command on all those instances. Is it possible to do this with automation?
If any one can give me a sample program for this, that would be helpful.
I am running Windows server 2008 on all those instances.
The Amazon EC2 Systems Manager Run Command can run commands on multiple Amazon EC2 instances.
It requires installation of an agent. Commands can then be run via the Management Console, AWS Command-Line Interface (CLI) or API calls.
I want to run a command in another server from my java code.
Ex. My project runs in under the server ip like ---- xx.xxx.xxx.xx
But I have to run command in another server which is like ---- .yyy.yy.yyy.yy (I am having all the credentials and access for this ip)
Is it possible? Any help would be appreciated.
Yes you can, one of the way:
On your target server(yyy.yyy.yyy.yyy), run a process that listens for commands from your client machine(xxx.xxx.xxx.xxx) . There are different ways to communicate between two remote jvms, you may chose any of them for example socket communication.
On target machine JVM, you can use ProcessBuilder to run the command received from client machine.
Or just some search for frameworks already available to such a task.
You could do it multiple ways, one way to create your own server client running on both instance and communicate it over some secure protocol to instruct remotely running agent to execute command
and if you don't want to re-invent wheel you can use SSH as underlying communication protocol and using sshj you can connect and execute command on remote machine
an example code that invokes ping command from remote machine and targetting google.com
I have an application which I can run locally via Putty. This lets me view and track activity on that application. I use the command below to execute the application:
java -jar my_server.jar
I would like to view the console of my application running on remote server. How would I do this?
Any pointers/help would be appropriated.
This question does not relate to either java or jconsole.
This is about terminal facilities. Putty is used to perform SSH connection. If the remote server is Unix like system you can use command screen to perform what you want. Take a look on Unix shell reference to learn how to use screen.
i'm trying to execute a shell script from a j2ee application (made with flash builder 3, spring, apache cxf) et get the result of its execution in my flex interface.
the problem is my application is on a windows 7 station and i don't know how i can execute the script on a distant unix server & get back the result.
i know that ssh apis can help but i've no idea how to get back the result.
any help will be welcome.
thanx
If you have ssh installed on your windows machine, you should be able to execute a command like
ssh user#remote_host ipconfig
This will execute ipconfig on the remote_host as user "user". You will need to do a bit of research into ssh so that you can make it so you can log in without using a password, but google will help with that.
Alternatively you could look in to a java implementation of ssh - jssh for example, although I confess that I have no experience of using that package.
To execute program from windows to unix you really need ssh or telnet.
SSH is more secure. You can do this without running external process. Use one of available pure java SSH libraries (e.g. javassh.org).
See examples. If you use this library your task is trivial. Just call appropriate API.
About the only reasonable and reasonably secure answer I could come up with is to configure ssh on both machines.
*nix boxes usually have ssh server installed by default.
Putty terminal emulation for windows comes with neat ssh client command line utility called plink which can execute shell commands on a remote unix box in a secure manner.