简体   繁体   中英

Executing iqisql using JSch fails with “An error occurred when attempting to allocate localization-related structures”

I have a requirement to run a script on remote machine for this I am using Jsch I cannot store the script in remote machine. below is the script

#!/bin/bash
/eniq/sybase_iq/OCS-15_0/bin/iqisql -Uce -Pce -Sendb -b -n <<EOF!

SELECT SUM(COUNTERS) FROM ADAPTER WHERE STARTTIME = "Aug  8 2016 11:30:00.000000PM"

go
exit
EOF!

if I run the script in Linux machine I am able to get the required outut

#: /eniq/sybase_iq/OCS-15_0/bin/iqisql -Uce -Pce -Sendb -b -n <<EOF!
> SELECT SUM(COUNTERS) FROM ADAPTER WHERE STARTTIME = "Aug  8 2016 11:30:00.000000PM"
> go
> exit
> EOF!
                                   168002

 (1 row affected)

But when I am trying to run the script using below java code -

package org.rhq.plugin.eniq;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

 import com.jcraft.jsch.Channel;
 import com.jcraft.jsch.ChannelExec;
 import com.jcraft.jsch.JSch;
 import com.jcraft.jsch.Session;

 public class JSchTest {

    private final Log log = LogFactory.getLog(JSchTest.class);

    public void executeCommand() {
        try {
            String command = "/eniq/sybase_iq/OCS-15_0/bin/iqisql -Uce -Pce -Sendb -b -n <<EOF!" + "\n"
                    + "SELECT SUM(COUNTERS) FROM ADAPTER WHERE STARTTIME = \"Aug  8 2016 11:30:00.000000PM\""
                    + "\n" +

                    "go" + "\n" + "exit" + "\n" + "EOF!";
            String host = "107.250.237.13";
            String user = "dcuser";
            String password = "dcuser";

            JSch jsch = new JSch();
            Session session = jsch.getSession(user, host, 22);
            Properties config = new Properties();
            config.put("StrictHostKeyChecking", "no");
            session.setConfig(config);
            ;
            session.setPassword(password);
            session.connect();

            Channel channel = session.openChannel("exec");
            ((ChannelExec) channel).setCommand(command);
            channel.setInputStream(null);
            ((ChannelExec) channel).setErrStream(System.err);

            InputStream input = channel.getInputStream();
            channel.connect();

            log.error("Channel Connected to machine " + host + " server with command: " + command);

            try {
                InputStreamReader inputReader = new InputStreamReader(input);
                BufferedReader bufferedReader = new BufferedReader(inputReader);
                String line = null;

                while ((line = bufferedReader.readLine()) != null) {
                    log.error("Eniq DB Output line is " + line);
                }
                bufferedReader.close();
                inputReader.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }

            channel.disconnect();
            session.disconnect();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

but when I run this I get the below error as outut- An error occurred when attempting to allocate localization-related structures

is something to do with locale name "en_US.UTF-8" ? how to set in jsch

NB: I cannot use sybase drivers in connection because of requirement dont permit

According to this previous StackOverflow answer

not able to run isql on cygwin

you should do

unset LANG

before running isql . So maybe same is true before running iqisql .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM