IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

execute shell script on 20 IS's

  • 1.  execute shell script on 20 IS's

    Posted Mon April 10, 2017 02:11 PM

    Hello,

    I started working on this recently and got into a trouble. Please help me on how to execute a shell script using a java service written in webMethods service development.

    So far my progress is as follows:
    I was able to login using ssh…verified on the unix shell and it is working.

    I am unable to do the following.
    cd to a specific directory and
    invoke the shell script.

    public static final void invokeOScommand(IData pipeline)
    throws ServiceException {
    IDataCursor idc = pipeline.getCursor();
    long connectionTimeout = 600;
    long readTimeOut = 600;
    String hostname = IDataUtil.getString( idc, “hostname” );
    String username = IDataUtil.getString( idc, “username” );
    String password = IDataUtil.getString( idc, “password” );
    String command = IDataUtil.getString( idc, “command” );
    //String commands = {“su - vkb”,“sh”};
    String directory = IDataUtil.getString( idc, “directory” );

    	String curr_status= null;
    
    try{
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    SshParameters sshParams = new SshParameters (hostname,username,password);
    Ssh ssh = new Ssh(sshParams);
    ssh.connect();				
    String status = "OK,Connected";
    
    // get OutputStream
    OutputStream out = ssh.getOutputStream();
    
    
    // define command to perform directory listing
    command = "sh startup.sh"; 
    
    // send command to SSH server
    out.write(command.getBytes());
    
    // write CRLF to indicate end of command
    out.write("\r\n".getBytes());
    
    
    IDataUtil.put( idc, "ssh_object", ssh );
    IDataUtil.put( idc, "status", status );
    
    }
    catch (Exception e) {
    throw new ServiceException("SystemLogger: Could not resolve syslog host. [java.net.UnknownHostException]");
    }
    

    #webMethods
    #Integration-Server-and-ESB


  • 2.  RE: execute shell script on 20 IS's

    Posted Mon April 10, 2017 02:12 PM

    Tried to use the firecommandexec but i was unable to make it work in Unix, ahy help would be appreciated,


    #Integration-Server-and-ESB
    #webMethods


  • 3.  RE: execute shell script on 20 IS's

    Posted Mon April 10, 2017 02:42 PM

    Hi Kama,

    can you explain your business requirement a bit more in detail please?

    Which wM version are you on?

    Regards,
    Holger


    #Integration-Server-and-ESB
    #webMethods


  • 4.  RE: execute shell script on 20 IS's

    Posted Mon April 10, 2017 02:53 PM

    using webMethods 9.6

    requirement was to cleanup all the logs in the IS’s each month after during restart . I have a unix script that has all the directories it need to go to and cleanup .This needs to be invoked without logging into the hosts and then traversing to the directory.My aim was to have a java service which can login to a unix host and then initiates that clean up script.

    Coming backto my questions, Integration Server is totaled at 20. I will have a flow which will over write hostname and port that can login to all the different 20 hosts.

    Hope i am clear enough


    #Integration-Server-and-ESB
    #webMethods


  • 5.  RE: execute shell script on 20 IS's

    Posted Tue April 11, 2017 06:36 AM

    Hi,

    What is the error you are receiving?

    Best Regards,


    #webMethods
    #Integration-Server-and-ESB


  • 6.  RE: execute shell script on 20 IS's

    Posted Tue April 11, 2017 01:18 PM

    problem is it doesn’t do ‘cd’ to that directory. where i have to issue that command.


    #webMethods
    #Integration-Server-and-ESB


  • 7.  RE: execute shell script on 20 IS's

    Posted Tue April 11, 2017 01:19 PM

    String commands = {“su - vkb”,“sh”}

    I was trying to make sure that it accepts these commands ,


    #Integration-Server-and-ESB
    #webMethods


  • 8.  RE: execute shell script on 20 IS's

    Posted Wed April 12, 2017 10:46 AM

    Hi,

    Can you use the built-in SSH File Transfer Protocol (SFTP) API in WmPublic/pub.client.sftp ?

    Best Regards


    #webMethods
    #Integration-Server-and-ESB


  • 9.  RE: execute shell script on 20 IS's

    Posted Wed April 12, 2017 11:16 AM

    Just trying to understand your logic here…

    So will the script you are building with JS needed to be executed on one IS that will handle all the other OS machines hosted IS’s log files clean up? Is that that direction you are going with?

    Yeh, why don’t you use WmPublic/pub.client.sftp service having with appropriate commands and manage the creds/path entries via a db?

    HTH,
    RMG


    #Integration-Server-and-ESB
    #webMethods


  • 10.  RE: execute shell script on 20 IS's

    Posted Wed April 12, 2017 12:17 PM

    @RMG

    Very true. I am trying to write this invokeOScommand service and place it on one box which then logs into other Integration servers(already shut) and cd to a directory where my cleanup script is residing. I do not know if i can use pub.client.sftp:cd,pub.client:sftp . I am not sure if these(pub.client…) will server my purpose of invoking a look alike of “sh cleanup.sh”


    #webMethods
    #Integration-Server-and-ESB


  • 11.  RE: execute shell script on 20 IS's

    Posted Wed April 12, 2017 12:22 PM

    The problem is the 20 integration servers that i am reachin out to are already in shutdown/disabled mode.


    #webMethods
    #Integration-Server-and-ESB


  • 12.  RE: execute shell script on 20 IS's

    Posted Wed April 12, 2017 12:23 PM

    I am not sure if i can use it in my scenario


    #Integration-Server-and-ESB
    #webMethods


  • 13.  RE: execute shell script on 20 IS's

    Posted Wed April 12, 2017 08:22 PM

    There is no other way , than to login to the unix box and invoke the shell script.
    Also , the problem is i have to have elevated rights to execute this cleanup. Which i get through using “su -”. I am trying to acheive the following.

    In sequential

    login to the host-i got it completed
    ‘su-’ not able to complete
    cd-not done
    sh cleanup.sh-not done


    #Integration-Server-and-ESB
    #webMethods


  • 14.  RE: execute shell script on 20 IS's

    Posted Wed April 12, 2017 10:08 PM

    Hi,

    Are you able to execute the operations manually (that is, opening an ssh session and sending each of the operations) from the machine where you have the IS?

    Can you execute the same operation through a script on that machine?

    Can you run that script from the IS?

    Best Regards,


    #webMethods
    #Integration-Server-and-ESB