AdminConfig.showAttribute from Java Code - java

I want to run the following wsadmin command from my java code.
AdminConfig.showAttribute('lp1(cells/iap/nodes/iapnode/servers/server1/server.xml#ListenerPort_1447149354628)', 'stateManagement')
I saw that there is a CommandMgr with AdminCommands, where I can set some parameters.
But I can't get out, which Command is the right one.
Can someone give me a code example, how to write the wsadmin command menitoned above in java-code?

Related

BPXWUNIX: not found error when trying to run Regina Rexx script

I have made a logfile reader in Java that is supposed to alert me via Xymon when more than 1 redis servers is down simultaneously.
Now I am supposed to feed the output to Xymon via a Rexx script and I tried to do that by calling the command to run the Java program using bpxwunix.
However, when I run the code to test it, it says: "sh: 1: BPXWUNIX not found".
I don't understand what I am doing wrong, I've been searching for a method to somehow include the bpxwunix function but it is my understanding that this is not necesarry.
I'm pretty sure the Rexx script is the problem because I tried a blank Java program that just prints a single line and got the same error. Also tried to just run the program in the command line with java -jar and it runs fine.
I am talking about Regina Rexx (even though it says oorexx and netrexx in the tags, I couldn't add a new rexx tag because my reputation was not high enough).
And I am trying this on Ubuntu 18.04.
Anyone that can help me out? Please alert me if I missed any details! The rexx code is provided below:
/* rexx */
env.0=1
env.1="/usr/bin:.:/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin:."
stdin.0=0
reader="/home/slave2/Downloads/LogFileReader.jar"
cmd="java -jar reader"
call bpxwunix cmd,stdin.,stdout.,stderr.,env.
SAY "stdout:"
exit
IBM provides BPXWUNIX as a built-in command in the z/OS operating system. If you're not running there — and your mention of Regina Rexx implies that you're not — then the command won't be available.

After exporting jar console doesn't show up

I have written a small program in Java in Eclipse, which outputs something in the console using System.out.println() and asks for input. When I export it, and run it, the command line doesn't show up though. It does do something, and when I run it via java -jar [filename] it does show the output in the command prompt. I know it does something because I work with an Access-database, and after opening a connection between the database and Java, there is created a .laccdb file, so something does happen. I don't see anything though.
I hope it is clear what I mean and I also hope someone can help me!
Apparently, when double-clicking on a .jar-file that only outputs in the command line will not show the command line. The only way to accomplish this is by running the jar with java -jar [filename].

Run some arguments in command line from java (using Eclipse)

Very basic command-line related question:
I have never tried to run anything in command line from java before and am struggling with the basics - other online information doesn't seem to work for my example, or I'm not understanding it.
In command line this is what it looks like:
C:\gnuplot\binary>gnuplot 15FebPlotFile.gp
All I have to do in command line is navigate to the correct file location (C:\gnuplot\binary) and then type gnuplot 15FebPlotFile.gp and it runs the thing I need (which simply generates a PDF and saves it to that file location)
I've seen people use Runtime and Process like on this site http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder.html but I don't understand how I call the various command, like cd C:\gnuplot\binary and then from that location get it to run gnuplot 15FebPlotFile.gp.
If anyone could give me any advice on an approriate site to look at or some lines of code that might help me I'd be really greatful.
Thank you
You can work with ProcessBuilder, and then you can set the working directory of the process using ProcessBuilder#directory(File dir):
ProcessBuilder processBuilder = new ProcessBuilder("gnuplot", "15FebPlotFile.gp");
processBuilder.directory(new File("C:\\gnuplot\\binary"));
Process p = processBuilder.start();
I hope here you can find some code examples and solutions
Run command prompt from java?
changing the working-directory of command from java

Trying to rename a computer OR execute a .bat file in Java

I'm trying to write a script to rename a computer (among other things) but just can't seem to figure it out. I don't really care what method I use to change the computer as long as i can change it. I found out how to read the computer name by doing
String computername = InetAddress.getLocalHost().getHostName();
However, that doesn't seem to offer any help in setting the computer name. Is there a way to set the Computer Name directly in the java console?
If not, or if anyone has better experience in this area, I also wrote a script using powershell 2.0 that renames the computer. I'm trying to figure out how to run that using
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("file location");
I followed the guide here but when trying to run a test .bat file that should just open the command line I just get this output in the java console:
C:\Users\Stephen\Desktop\opencmd.bat is found
OUTPUT>
OUTPUT>C:\Users\Stephen\workspace\UNM computer rename>cmd.exe
OUTPUT>Microsoft Windows [Version 6.1.7601]
OUTPUT>Copyright (c) 2009 Microsoft Corporation. All rights reserved.
OUTPUT>
It looks like it's just spitting back the command line output into the java console, instead of just running the command and opening the cmd line.
I would really appreciate input as I'm in a crunch for time here, thanks!
First, JDK really does not provide pure java API that allows changing computer name. So you have to run script.
Second, if you want to run script using Runtime you have to provide correct command line. So first try to run your script manually. I believe it accepts a least one parameter (the new computer name). So run it from command prompt and see it is working. Then put it to the working directory of your java program and copy/paste the command line into the java code and see that it is working now. if you want you can read STDOUT of your script and/or get its return code. If you do not care about its output just call process.waitFor() and then get the return code.
Be careful with arguments. Windows computer name may contain unicode characters and spaces. If it contains spaces surround it with quotes. Concerning unicode just try. I hope it will not cause problems to you.
You can also use ProcessBuilder class that allows better and more portable arguments passing.
Good luck.
It looks like opencmd.bat is being executed, so assuming your PowerShell script works, is it possible you don't have administrative privileges?
You can also do it elegantly using JNA, I think this would be the target. But if you are rushed for time, don't bother.

Intercepting PHP mail() with a Java class

I have a LAMP setup. I'm trying to intercept the mail() command and call my own Java code instead of calling sendmail etc. I've altered the php.ini
sendmail_path = /home/jlarkins/Desktop/CustomMail
which is my Java class file. Problem is, whenever I try to test this via a PHP test emailer, nothing happens. Can someone help me out, point me to the proper log file for Java errors or correct the syntax I'm using? I don't care that it won't send the email, I don't want the email going out anyways. I just want to trap it and analyze via my own Java code.
First, check your PHP/Apache error log file to see if anything can be found there.
Is "CustomMail" a .class file? If yes, it is not an executable file, thus PHP cannot run it. You'll have to point your sendmail_path variable on an executable file which will load your Java program and forward its arguments.
Something like this should work:
#!/bin/sh
[ -r CustomMail.class ] && java CustomMail $#

Categories

Resources