I want to start workflow from JAVA. I connect to informatica server using SSH and execute the command pmcmd to start workflow
JSch js = new JSch();
Session s = js.getSession("username", "host", 22);
s.setPassword("password");
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
s.setConfig(config);
s.connect();
Channel c = s.openChannel("exec");
ChannelExec ce = (ChannelExec) c;
ce.setCommand("pmcmd startworkflow -sv integrationservice -d Domain_dwhetl -u user -p pass-usd hq -f dvl wf_test");
//ce.setCommand("find -name PMCMD");
ce.setErrStream(System.err);
ce.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(ce.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
ce.disconnect();
s.disconnect();
System.out.println("Exit code: " + ce.getExitStatus());
When I run this I'm getting the error : bash: pmcmd: command not found.
If I add path to pmcmd.exe:
ce.setCommand("/PMRootDir/pmcmd startworkflow -sv integrationservice -d Domain_dwhetl -u user -p pass-usd hq -f dvl wf_test");
I get the error: /PMRootDir/pmcmd: error while loading shared libraries: libpmasrt.so: cannot open shared object file: No such file or directory
But when I run those commands in informatica server directly the workflow starts successfully.
Cand anyone help to solve this problem?
Thank you!
You have set the PATH to where Informatica is installed, or more specifically the directory the pmcmd executable is present.
Add the export command before calling pmcmd.
export PATH=<path Infa installation directory>:$PATH;
#Samik, Thank you!
I've added this
"export INFA_HOME=<path Infa installation directory>; " +
"export PM_HOME=<path Infa installation directory>; " +
"export PATH=$PATH:<path Infa installation directory>/server/bin; " +
"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path Infa installation directory>/server/bin; "
and it worked
You need to set Environment Variable Path
Example
export PATH=$PATH:/pwc/Informatica/10.2/server/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/pwc/Informatica/10.2/server/bi
Related
I have a java program that does some preparation and then invokes Jekyll on the content it's prepared. Jekyll is a Ruby program installed on the local PC as a gem. On windows and linux, no problem, but when running on OSX, under the eclipse debugger, Jekyll doesn't run. Presumably this is because of interactive shell issues (Jekyll runs fine from the terminal).
Here's my java code:
DefaultExecutor exec = new DefaultExecutor(); // from org.apache.commons.exec
exec.setExitValue(0);
MyFilterHandler pumpHandler = new MyFilterHandler();
exec.setWorkingDirectory(new File("/Users/grahamegrieve/temp/igs/swissnoso/temp/pages"));
ProcessBuilder processBuilder = new ProcessBuilder(new String("bash -c jekyll build --destination /Users/grahamegrieve/temp/igs/swissnoso/output"));
Map<String, String> env = processBuilder.environment();
Map<String, String> vars = new HashMap<>();
vars.putAll(env);
String path = "/Users/grahamegrieve/.gem/ruby/3.1.0/bin:/Users/grahamegrieve/.gem/ruby/3.1.0/bin:/opt/homebrew/opt/ruby/bin:/Users/grahamegrieve/.nvm/versions/node/v17.4.0/bin:/opt/homebrew/bin:/opt/homebrew/sbin:"+env.get("PATH");
vars.put("PATH", path);
exec.execute(org.apache.commons.exec.CommandLine.parse("bash -c -i jekyll build --destination /Users/grahamegrieve/temp/igs/swissnoso/output"), vars);
this results in the following output from the process:
A subcommand is required.
followed by Jekyll's standard documentation - so Jekyll is running but not getting the parameters. The same thing happens in terminal:
➜ ~ bash -c jekyll build --destination /Users/grahamegrieve/temp/igs/swissnoso/output
A subcommand is required.
jekyll 4.2.1 -- Jekyll is a blog-aware, static site generator in Ruby
Usage:
jekyll <subcommand> [options]
In the terminal, I can do this:
➜ ~ bash -c 'jekyll build --destination /Users/grahamegrieve/temp/igs/swissnoso/output'
Configuration file: none
Source: /Users/grahamegrieve
Destination: /Users/grahamegrieve/temp/igs/swissnoso/output
Incremental build: disabled. Enable with --incremental
Generating...
so the parameters work fine when the entire command is wrapped in ''. But putting '' (or "") in the java code results in
Jekyll: bash: jekyll build --destination /Users/grahamegrieve/temp/igs/swissnoso/output: No such file or directory
As far as I can tell, that means there is no file with the name 'Jekyll build ...'.
So I don't know how to invoke Jekyll from my java code on OSX. Is it possible?
The answer is over here: execute shell command with org.apache.commons.exec.DefaultExecutor
It's to do with the way CommandLine works, and interacts with Bash.
DefaultExecutor exec = new DefaultExecutor(); // from org.apache.commons.exec
exec.setExitValue(0);
MyFilterHandler pumpHandler = new MyFilterHandler();
exec.setWorkingDirectory(new File("/Users/grahamegrieve/temp/igs/swissnoso/temp/pages"));
ProcessBuilder processBuilder = new ProcessBuilder(new String("bash -c jekyll build --destination /Users/grahamegrieve/temp/igs/swissnoso/output"));
Map<String, String> env = processBuilder.environment();
Map<String, String> vars = new HashMap<>();
vars.putAll(env);
String path = "/Users/grahamegrieve/.gem/ruby/3.1.0/bin:/Users/grahamegrieve/.gem/ruby/3.1.0/bin:/opt/homebrew/opt/ruby/bin:/Users/grahamegrieve/.nvm/versions/node/v17.4.0/bin:/opt/homebrew/bin:/opt/homebrew/sbin:"+env.get("PATH");
vars.put("PATH", path);
CommandLine cmd = new CommandLine("bash").addArgument("-c").addArgument("Jekyll build --destination /Users/grahamegrieve/temp/igs/swissnoso/output", false);
exec.execute(cmd, vars);
I am trying to run following command on AIX to backup files occasionally.
tar cvf - /tmp/emflextmp/* |gzip > /APP/emflex/scada/Db/backup/dbBackup_31_Aug_2019__15_51_04.tar.gz
If I run this command on terminal through same login it works perfectly. Now I want to do it through the java app. My code looks like this:
Process process = Runtime.getRuntime().exec("tar cvf - "+tempFolder+"* |gzip > " + strBackupFolder + File.separator + "dbBackup_" + new SimpleDateFormat("dd_MMM_yyyy__HH_mm_ss").format(new Date()) + ".tar.gz" );
int exitVal = process.waitFor();
I get exit code 2 here.
From logs the command looks ok
2019-08-31 15:51:04:565 [INFO.] [Thread-16:ID=76]:[GarbageCollector.java:332] Running H2 Database Backup Command On AIX =[tar cvf - /tmp/emflextmp/* |gzip > /APP/emflex/scada/Db/backup/dbBackup_31_Aug_2019__15_51_04.tar.gz]
None of the output files are created. What is the problem here?
I have just switched over to working on a mac and I am trying to determine why I am unable to get Eclipse to recognize the binary I am trying to run via a ProcessBuilder.
I have tried to run it both as a Java Application in Eclipse and as a TestNG test.
If I compile the class with java and run it directly from the command line it will work but not through Eclipse which leads me to believe the configuration for the $PATH is not setup correctly in my TestNG configuration.
Question
I am sure this is a configuration issue within Eclipse but after searching for a day and coming up short I wanted to post for some help. I have tried to set $PATH on the configuration but it does not seem to work.
Thank you
Update /Answer
It turned out that the PATH I had set on the shell shown below was not the same that Java had which I checked using the code below. After verifying that I then added the proper path to my environment on the ProcessBuilder and executed the script as shown in the answer.
Map<String, String> env = processBuilder.environment();
for (String key : env.keySet())
System.out.println(key + ": " + env.get(key));
Map<String, String> envs = processBuilder.environment();
System.out.println("Path " + envs.get("PATH"));
envs.put("PATH", "/usr/local/bin");
System.out.println("PATH " + envs.get("PATH"));
Code
File logsDir = new File(logDirectory);
if (!logsDir.exists()) {
logsDir.mkdirs();
}
// run process directly
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("appium");
processBuilder.redirectError(new File(logsDir, "appiumError.txt"));
processBuilder.redirectOutput(new File(logsDir, "appiumOutput.txt"));
process = processBuilder.start();
Output (it cannot find node to run appium hence the No such file or directory)
Caused by: java.io.IOException: Cannot run program "appium": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at AppiumService.startAppium(AppiumService.java:77)
Path (The bin for node and appium is in /usr/local/bin)
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:
/usr/local/opt/ant/bin:/usr/local/opt/maven/bin:
/usr/local/opt/gradle/bin
The PATH variable of the java-process might be explicitly set by Eclipse not containing the paths you need. You can call the command using the absolute path to the corresponding directory or you might try using a shell to start the process by creating the process with
processBuilder.command("/bin/sh", "-c", "appium");
I have a rest service written in java on linux machine.
I'm using:
p = Runtime.getRuntime().exec(cmmnd);
or
ProcessBuilder pb = new ProcessBuilder(cmmnd).inheritIO();
p = pb.start();
p.waitFor();
I can execute commands like mkdir, touch ...
But when i try to run sh file nothing happens (for example: sudo sh /home/mydir/myfile.sh)
Is it a permission issue? How can I resolve that?
Only file execution permission is not suffice here. First run the command sudo sh /home/mydir/myfile.sh from command prompt manually and check whether work or not? Is you sodo ask for a password? Is your web service account from where you are executing the command has permission to execute as sudo? Also check whether your web application has file access permission to location (means can it execute cd /home/mydir/) /home/mydir/myfile.sh or not?
Also in your code read the output and check what is the actual error?
p.getOutputStream();
Also try with:-
ProcessBuilder pb = new ProcessBuilder("sudo sh /home/mydir/myfile.sh");
pb.redirectOutput(new File("/new_path/out.txt"));
Process p = pb.start();
try {
p.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
I'm unsuccessful with combining "Sudo" and "ScpTo" cases.
I noticed, that both work through "exec" channel.
Clean "ScpTo" case finishes with "Permission denied" message.
"Sudo" case
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand("sudo -S -u <supervisor> whoami");
works fine.
When I connect to my server through FarManager I write server option:
sudo su -l <supervisor> -c /usr/libexec/openssh/sftp-server
Also, I can run usual SFTP client like this:
sftp -s 'sudo su -l <supervisor> -c /usr/libexec/openssh/sftp-server' "usual user"#"host"
and give put command.
But such option (-s) is not implemented in JSch.
How can I configure my case (Sudo & ScpTo) with JSch?
In ScpTo.java example, there's this code:
String command="scp " + (ptimestamp ? "-p" :"") +" -t "+rfile;
Change that to:
String command="sudo su -l <supervisor> -c scp " + (ptimestamp ? "-p" :"") +" -t "+rfile;