I have searched all over but found no luck yet, I am using linux ubuntu flavour and need to know that how can I check that whether the java jar file is running at remote end or not using pgrep. As the pgrep -f "someProcess" returns the Process ID.
Note: Both systems are linux based, and I only need to done it through terminal. Any ideas would be appreciated.
I've used Ant to do this.
I can't remember which task I used unfortunately....
But we executed a command or script remotely using an ant task.
I think we used ExecTask.
Notice you can specify an output file.
You can read that to process the output of your command.
Ant is pretty awesome in that anything you can do with an Ant script, you can do with Java.
And it's a lot easier than you'd think.
I believe this is a good starting pont to learn how to do it.
Here is the Javadoc overview page for the Ant classes.
Here are some more links to helpful Javadoc pages:
Project
Task (the base class for all Ant tasks)
SSHExec task (looks like this is what you want)
ExecTask
Copy task (this is a nice simple one for "Hello, World" purposes
FTP task
I'm sure there other ways, but as they say here Ant makes things very easy for you.
I can think of one way to do this.
Assuming you have servers A and B, A performs the process check on B. You can use ssh and setup no-password login from A->B and use command below:
ssh root#12.34.56.78 "pgrep [whatever keyword]"
You'll get the same result as executing the command on B.
You could use plink.exe to do this. You can pass commands to plink in the form of a .txt file input.
Related
I'm building a desktop app that uses Cygwin to execute shell scripts on Windows 10. Ideally, users wouldn't have to install Cygwin because I'm putting the relevant exe files in my project. I have Cygwin's "sh.exe" in my project which I can call without an absolute path and it seems to be running grep, zcat, awk, etc with no issues.
It looks like I'm running into the issue explained in https://www.question-defense.com/2010/08/25/windows-7-cygwin-sort-input-file-specified-two-times where Window's cmd is using it's own sort rather than Cygwin's sort.exe and you have to put the path of the sort.exe in the script. So it looks like the user would have to download Cygwin which would somewhat defeats the purpose of my project because I want a hassle-free experience for users. I don't want them to have to download dependencies.
The only resolution I've thought of is to include the sort.exe in the project and replace the "sort" string in the script with the Windows path of the sort.exe, which I think would be in the directory where the user launched the app; maybe System.getProperty("user.dir").
Is there a better solution?
MobaXTerm seems to have got it down. They have a CygUtils plugin, which you have to download and put in the right place, but I imagine it wouldn't be hard for them to have their application come with CygUtils. I'm trying to do something like that.
I faced same issue while using Cygwin.
I renamed [cygwin64_folder]\bin\sort file to csort (or any other convenient name if you wish) and used csort command for my usage.
I've been working on my jenkins server off and on for the last few weeks. Right now it runs fine building and outputting the files to a remote location. However, i'm looking to do some pass or fail tests on the files before they are uploaded. This way i avoid releasing broken versions of my work. As well avoid more bug reports that i do not need to be reading.
The files i'm looking to run are actually plugins for another program. So i need to actually start this program as i can configure all the files before hand. The program is a .jar file which i know i can launch using a bat of shell script. The issue is i don't know at this point how to terminate the .jar program after it has been running. All the solutions i've found require me to modify the jar to terminate itself, or kill the JVM. Both i can't due for varies reasons.
It's a heavy hack, but you can make a shell script start a background thread that checks if the JVM is done, then terminate it.
Rudimentary example in bash:
start_jvm_command >>console.log 2>&1 </dev/null &
while ! grep 'done signal' console.log; do sleep 1; done
pkill -f "regexp for start_jvm_command"
Note: I was using pkill to terminate to avoid wrapper shell scripts.
It been a year since i asked this question but i found a much nicer way to solve this question. Its called JUnit and is a testing lib for java. With it i don't need to launch the entire jar but can test peace by peace at a time. As well if require i can write a test to launch the entire .jar file. In the test i can check if files exist, if functions complete correctly, and if any error is thrown during runtime.
so, I've been doing some searching, and i can find somethings on how to run an external application, but i cant get them to work! I've been working on this for a while, and its really annoying.
what i want to do is run a .jar file in the directory
C:\Program Files\AVTECH\NPS\Files\bin\NPS.jar
and I've tried a bunch of different things with the code
Process p = Runtime.getRuntime().exec("dir goes here");.
also
Process p = Runtime.getRuntime().exec("C:\\Program Files\\AVTECH\NPS\\Files\\bin\\NPS.jar");.
if i'm correct, it uses command prompt to do this? or at least the MS-DOS language. i did some of that kind of thing a few years ago, but i don't remember how one would do this... I've never worked with this kind of thing in java before...
could someone help please? thanks in advance.
Runtime.exec() is working just like if you were typing a command.
Launching a jar file is not working : you have to invoke
java -jar /path/to/my/jar
Check Oracle's documentation on how to execute a jar file.
The actual command should be java -jar C:\\Program Files\\AVTECH\NPS\\Files\\bin\\NPS.jar. I mean -- if the jar file is indeed executable, this doesn't mean it will run, by just trying to invoke it. You need to tell Java to run it as shown above.
In addition, MS-DOS is not a language -- it stands for Microsoft Disk Operating System. Nowadays, you have this as a Command-line Prompt (Shell) built into Windows.
You need to run the command as a call to the executable and a set of arguments. Check this version of Runtime.exec(String[] cmdarray). If need be, there's also a version of Runtime.exec() that takes a base directory in which to start the executable.
I'll appreciate any help .
I created the shell script that collects servers IP - members of weblogic cluster to distribute some files across all servers in list.
I prepared a special ANT task for distribution and call this task from another shell script . Each time I call the ANT task I pass the next server IP to copy files on it.
This behaviour brings the installation structure.
Now I'd like to improve this behaviour . I want in ANT to read the output of the shell file to some list that I can loop thru from the ANT task.
Thanks
You can simply use the outputproperty attribute of the exec ant task. See http://ant.apache.org/manual/Tasks/exec.html for the full documentation. With this, you can also handle standard error output.
Once the script output is in an ant property, you can iterate on it using ant contrib foreach task foreach task.
How to implement the Linux 'top command' style UI using JAVA?
And How to run jar in server side itself, and i can see the state of the program after i log in SSH.
For your second question:
java -jar jarfile.jar
Will run a jar file that is written to be run at the command line. Anything this program prints to standard out will be displayed for you to see.
This entry talks a bit about building a jar file that can be run in this way:
http://en.wikipedia.org/wiki/JAR_%28file_format%29
You could give this a try. I'm assuming that you're looking for an ASCII terminal UI toolkit... which I'd recommend, because terminal codes are rather painful to write by hand.
You might be looking for a Java Curses Framework like this:
http://javacurses.sourceforge.net or CHARVA