How to execute a CMD command on multiple EC2 Windows instance? - java

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.

Related

Run CMD as Administrator in java without password

I need to run the following command using java:
"wmic product where description='" + someProgram + "' uninstall"
This CMD works only when running as Administrator.
This program will run in several machines with different passwords, so I can't insert passwords in my program.
How can I run it as Admin, without running the whole program as administrator?
Edit:
This program runs on a local Windows machine (no dealing with remotes)
I believe it is possible in Unix for your Admin to write to write a Shell Script which runs with the priveleges of another User-ID & which members of the Group (or Anyone) may start.
See: Setuid & chmod
If you are looking for a remote solution (where the Java makes say an SSH connection to the remote and then runs the command), then can't you configure the process running on those machines - providing the SSH server - so it runs commands as an appropriately privileged user?
AND/OR find a localgroup that gives the permissions you need?

How to get user count on a EC2 Windows Instance AWS

I'm trying to incorporate some AWS features into my JSF application. I have multiple EC2 instances running windows server, I would like to know how many windows users are connected to each instance and if they are actively using the system or not.
That info will be further used to create and terminate instances on the fly. I've tried using a ELB, but there is no metric for number of users connected and if they are active or not.
Currently I'm using the Java AWS SDK 1.11.657 due to some application constraints. Given that I have a list of my instances and power to create and terminate them, how would I go about finding the number of users connected to each instance? Did not find anything online using the Java SDK. Thank you.
You can use the Remote Desktop Services API/SDK or PowerShell cmdlet (Get-RDUserSession) to determine the count of active RDP sessions. There's also, allegedly, a more sophisticated cross-server PowerShell script.
To remotely invoke PowerShell scripts on Windows instances, you can use SSM Run Command. Here's an example of using the awscli to do this:
aws ssm send-command \
--document-name "AWS-RunShellScript" \
--comment "List Windows services" \
--instance-ids "i-1234567890,i-0987654321" \
--parameters commands="service --status-all" \
--output text
Note that your Windows instances need to be set up in advance to support this so see this tutorial. It's likely Linux-oriented but hopefully this gets you started in the right direction.

how to login and create file in ec2 using java code

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.

run process (command) on a remote linux machine from java

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

Running command line on a remote machine using Java

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

Categories

Resources