I have a windows machine which connects to a remote Linux machine where my Java program is running. How could I run a command for example, "free -m" in the remote linux machine and collects data in the windows machine. Any strategy?
You can execute Linux command from java program remotely using Jsch and expect4j.
For example, look at this question.
You can use ssh user#host free -m. Just get some ssh client for windows. I personally prefer cygwin which will also give you a nice way to script it using bash.
If you use anything except jsch, you run the risk of blasphemy :)
I have previously used Trilead SSH which was great and simple to use. Unfortunately Trilead don't support it anymore, however according to this site (lots of SSH links there) the ex-Trilead version is now here.
Related
Hi I have the jsl tool (http://jslwin.sourceforge.net/index.html) already in the code to run the java process on windows as services.
But now the requirement is to run the java process as a service on Linux machine.
I have tried to run the code on Linux and getting no error/exception at run time. But as of now I am not sure this is working properly or not.
So my question is , can this tool be used on Linux machine as well?
Someone can tell me the best way, through a web Java application, how to run an application on a remote machine (linux) and how to know if this application has already completed. I know the application terminates automatically, so just wanted to wait for the answer.
any help or advice are very welcome.
I was confused by the wording, so I will assume the following: the web application and the remote application are running on two different machines, with the remote application on Linux.
If that is the case, then you would be better off using a SSH library for Java (there are several - JSch, sshj, Ganymed SSH-2, to connect to the remote machine and run commands on it. This is a better approach than using ProcessBuilder, for it abstracts you from the problem of providing your password to the terminal (which can get quite tricky).
I'm not sure what you meant by this statement: "I know the application terminates automatically, so just wanted to wait for the answer." so I'll make another assumption that you want to know if the remote process terminated successfully or not. I'm unsure if any of the SSH libraries posted above, will allow you to get the remote process status in a non-trivial way, so you are better off writing a shell wrapper to your remote command that will return a parseable message.
If you are running both on the same machine, use ProcessBuilder.
I have here a Windows distribution server that runs an ANT task to build enterprise software. What I need to do is to have the ANT task copy and run a VM image (Linux), and then...talk to that Linux VM through the host operating system (through the ant task itself). We need to be able to send files and/or commands to it.
Is there a practical way to go about this? I know that we already have a way to send commands to VMs that are also running Windows (so windows-windows interaction) -- but is there a way to do a windows-linux interaction?
I've implemented the thing you wanted. Of course, for my own purposes, and then just found this question by googling on keywords "vmware" and "ant".
https://github.com/zhuravlik/ant-vix-tasks
This is the taskset for Ant to manage VMWare VMs.
It works via VIX API, so Linux guests should be supported by it.
I did not test it with VMWare Server, though. Only with Workstation.
But the API is common, so it should work.
Using ssh is probably the simplest. There is an ant task for that. Scp task is also there to copy files
It will depend on what you need to do, but:
The Linux system could expose an SSH server, and the host can do just about anything it needs to via SSH.
The Linux system could expose a web service that the host consumes.
The Linux system could expose a Samba share which the host then connects to and reads/writes from (if all you need to do is deal with some files, but that seems unlikely).
There are probably dozens of options.
I'm on Windows Vista 64 bit, with a 64 bit jvm installed. I'm trying to use jstack and jmap -- two utilities that come with the JDK -- to peek into an application server's guts. This works fine on a windows xp machine, 32 bit.
However, when I run these commands against the processid for a ColdFusion application server on this vista64 machine, I get the error message in the title of this post.
All I'm doing is running jstack , where pid is the processid of my CF server, and I'm getting this
this machine has plenty of available memory, but I highly doubt it's a memory problem. The reason I say that is that if I start JBoss, which is taking up just as much memory as CF, I can run jstack against that process.
Thanks for advice
Figured it out. The problem was that ColdFusion was running as a windows service. By stopping the service and running from the command line (jrun start cfusion) , I was able to successfully use the JDK tools
this posting provides details on how to execute jstack when the process is running as a windows service. basically, use the psexec command.
Jstack and Not enough storage is available to process this command
I'm trying to run jstack command on my java application. Application is rather big, running inside jboss AS occupying about 4gb of memory. OS is Windows Server 2003 Standard edition. Every time i get an error "Not enough storage is available to process this command". There is enough ram, 16gb, and disk space. So, any ideas?
I ran into this recently on Win2008r2 and thought I'd share my solution since it took a while to figure out. Rob's comment about psexec -s is what did it for me.
It appears that on Vista and later jstack doesn't work against services because of the user context. It has nothing to do with memory. I suspect this is the same reason people have seen this problem on 2003 via remote desktop, unless you use the /admin or /console switch on mstsc. As of Vista the tightened security is probably what broke it.
Starting my app from a cmd window worked fine, but that doesn't help me debug our standard install. Enabling the java debug port (for VisualVM, Eclipse or most any Java debugger) requires an app restart, so you lose the state you're probably trying to capture if you don't already have debugging enabled. Starting the service under my user credentials did not work - I was a little surprised at that. But psexec -s runs jstack from the system context, which worked like a charm. Oh, and you'll need to run psexec from an elevated cmd prompt, if UAC is on.
In the past I have seen this when the JVM is running as a Windows Service on Windows 2003.
First, check to see if this is an issue with the TMP directory.
Second, jstack (or the other utilities like jconsole) will not connect to the local process unless it is running in the same session. If the service is running as a specific user, you may be able to connect by logging into the same session. If you are using Remote Desktop, you can connect using "mstsc /admin" (used to be /console) and try to run jstack again. Definitely check to make sure the TMP directory is set properly if this doesn't fix the problem.
If the service is running as LocalSystem, the above procedure probably will not help much. I don't know if there is a way to log into the same session as LocalSystem.
Some other alternatives may be to set the process up for remote monitoring and use jvisualvm (from the server itself or another machine) to connect over a port and do a thread dump.
We had problems running JStack on a Windows machine with even a modest application (1GB). We ended up doing our stack and heap analysis using Netbeans. This seemed to cope with the parsing of dump files a lot better. YMMV.
Give Netbeans a try for profiling - its very good. Note that VisualVM is a cutdown NB profiler and comes with 6u7.
psexec -s jstack PID >> c:\jstack.log perfectly works on the same machine. For the first time it took some time but again I executed with the redirect to file option, it completed with in few seconds.
This is an error message from the underlying O/S. There's not much you can do in your code to deal with this other than catch the exception which is thrown. Boo to Windows for being so limited.
http://technet.microsoft.com/en-us/library/cc978735.aspx