Maximo List Archive

This is an archive of the Maximo Yahoo Community. The content of this pages may be a sometimes obsolete so please check post dates.
Thanks to the community owner Christopher Wanko for providing the content.



Executing a shell command through Maximo

From: pranjal149 (2014-08-22 13:39)

Can we execute a shell command in an AIX environment from maximo through an automation script or java class? I saw an article on executing a program or possible a cmd batch file in windows from maximo through configuration but it was specifically for windows environment. Is there anything for AIX?


From: maxvil (2014-08-26 06:38)

I also had recently the need to execute a batch script (production server was running on Red Had Linux in my case) from a custom maximo ui bean class, it worked without particular problems apart some security considerations to take into account, this is what I used during the execute method of a custom DataBean class if it's useful for you.

try {
myLogger.debug("Bean.execute() About to Send Files");
Runtime.getRuntime().exec("chmod a+x ./transfer.sh");
Runtime.getRuntime().exec("./transfer.sh");
}
catch (Exception e3)
{
e3.printStackTrace();
myLogger.debug("Bean.execute() e3=" + e3.getMessage());
}
I tested this approach on windows and red hat, not on Aix, but I'm confident it will work as in the Linux env.
You have to take into account some aspects, particularly for *nix environments, I try to recall them here:
It's the WebSphere or other app server process that actually issue the batch script, so the user is the wasadmin or other configured, not root, so you might in principle had permission problems that could appear as application problems. There are workarounds for this if needed.

I suggest you locate initially the script you are going to launch in the app server path, usually /opt/ibm/WebSphere/AppServer/profiles/ctgAppSrv01/, the other advantage is that if the script is in that path, you can address it's name in the code just with prepending ./ like in the code snippet because for Massimo that is the root path.

I cannot help on other tecniques, ma according to documentation you can run a batch script or executables also from a Maximo Action, I never tried that, but also several products built on Maximo Base uses this other approach.

Hope this helps
Massimo Villani


From: pranjal149 (2014-08-26 08:35)

Thanks Massimo. I'll try it out. If I not wrong, you executed this on the websphere Linux server, did you try connecting to a different linux server and executing the script?


From: maxvil (2014-08-27 08:08)

I think you can only launch an executable or script from the maximo server. But, for example in my case, you can put in the local maximo server script the commands to issue a remote command.
In my case the transfer.sh was launching series of scp commands, you can just isuue an rsh or similar instead with parameters to launch scripts on remote servers.

Best Regards
Massimo


From: Hanna, Christopher A CTR (2014-09-02 16:22)

I'm sure you "could" using Java code, in a past life I did a similar thing, executing a shell script on a Unix server from within an Oracle PL/SQL routine. However I can tell you from experience that such A thing will be problematic to maintain. If you can, I would just re-write your shell logic directly into Java class, or maybe even automation scripting can handle it.
-----Original Message-----
From: MAXIMO@yahoogroups.com [mailto:MAXIMO@yahoogroups.com]
Sent: Friday, August 22, 2014 4:40 PM
To: MAXIMO@yahoogroups.com
Subject: [MAXIMO List] Executing a shell command through Maximo

Can we execute a shell command in an AIX environment from maximo through an automation script or java class? I saw an article on executing a program or possible a cmd batch file in windows from maximo through configuration but it was specifically for windows environment. Is there anything for AIX?


From: pranjal149 (2014-09-04 11:02)

@Christopher - Yes I am trying that from scripting only but somehow all the commands are not working for me.
@Massimo - How do I issue a remote call? even if I copy the script file to the remote server through scp, how do I execute it on the remote server?

Also I found some libraries in maximo(lib) to do SSH. SSHProtocol is one class that can be used to connect to unix server and execute commands on that server but again all the commands are not working. There are 2 methods in that class - exec() and run() that can be used to run commands but when I try to run db2 commands like db2move or db2look or even try to execute a shell script on the unix box they are not working.

Anybody tried using SSHProtocol or any other lib that is already available in maximo framework or if anybody can give me an example how to do run commands in unix server, would be much appreciated.

Thanks


From: Ian Wright (2014-09-05 07:55)

I've never tried it but why not just use standard java
Runtime.getRuntime().exec(myCommand);
1. import java.io.*;
2. public class TestExec {
3. public static void main(String[] args) {
4. try {
5. Process p = Runtime.getRuntime().exec("cmd /C dir");
6. BufferedReader in = new BufferedReader(
7. new InputStreamReader(p.getInputStream()));
8. String line = null;
9. while ((line = in.readLine()) != null) {
10. System.out.println(line);
11. }
12. } catch (IOException e) {
13. e.printStackTrace();
14. }
15. }
16. }
From: MAXIMO@yahoogroups.com [mailto:MAXIMO@yahoogroups.com]
Sent: 04 September 2014 19:03
To: MAXIMO@yahoogroups.com
Subject: [MAXIMO List] Re: Executing a shell command through Maximo
@Christopher - Yes I am trying that from scripting only but somehow all the commands are not working for me.
@Massimo - How do I issue a remote call? even if I copy the script file to the remote server through scp, how do I execute it on the remote server?
Also I found some libraries in maximo(lib) to do SSH. SSHProtocol is one class that can be used to connect to unix server and execute commands on that server but again all the commands are not working. There are 2 methods in that class - exec() and run() that can be used to run commands but when I try to run db2 commands like db2move or db2look or even try to execute a shell script on the unix box they are not working.
Anybody tried using SSHProtocol or any other lib that is already available in maximo framework or if anybody can give me an example how to do run commands in unix server, would be much appreciated.
Thanks
GDF SUEZ E&P UK Ltd (Company Number 3386464), registered in England and Wales with a registered office address at: 40 Holborn Viaduct, London, EC1N 2PB.
**************************************************************************************************************
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the system manager.
**************************************************************************************************************


From: pranjal149 (2014-09-07 08:46)

Ian,
We have tried Runtime.getRuntime().exec(), it gets you the runtime of the application server on which the jvm is running.

We need to execute some database move commands on the database server. So we connected to the database server from the application server through runtime using ssh and tried executing a shell script which contained all the database move commands then we wanted to execute on the database. But somehow its not recognizing the commands in the shell script when we execute them through ssh. If we login to the database server and then execute the shell script, it executed perfectly. So I an trying to explore other options.


From: maxvil (2014-09-09 10:42)


Hello,
my minimalistic suggestion (if you managed to make the library work would be surely better) was to launch with the method I already posted a script local for maximo server, for example transfer_execute.sh.

Inside the transfer_execute.sh script you can code the transfter and remote execution comands, eg.:

scp myscript.sh remote_server.com://var
rsh -l username remote_server.com: /var/myscript.sh

or

scp myscript.sh remote_server.com://var
ssh username@remote_server.com /var/myscript.sh

according to with remote commands are possible (rsh or ssh or other) is configured or allowe in your aix environment.

When I used this approach with maximo, I created from the java bean also the transfer_execute.sh script with dynamic information (like username, password, path, filenames) from the maximo records, executed it and then removed the script because I had to include also password info in clear for limitation of my environment. If you environment is properly configured (for example with ssh across different nodes) you can avoid to include password/user info.
I understand it's rudimentary, but should work.

Hope this helps.
Massimo Villani