简体   繁体   English

JAVA - 从终端执行但不通过 JAVA 代码执行的 .sh 文件

[英]JAVA - .sh file executing from terminal but not via JAVA code

I have a JAVA code to create and execute .sh file.我有一个 JAVA 代码来创建和执行 .sh 文件。 The problem is - .sh file is getting created but not getting executed via the JAVA code.问题是 - .sh 文件正在创建,但没有通过 JAVA 代码执行。 When run manually from terminal or cronjob, it gets executed.当从终端或 cronjob 手动运行时,它会被执行。 The big problem is - same code is working fine on all DEV servers but not on client PROD environment with CentOS 6.8.最大的问题是 - 相同的代码在所有 DEV 服务器上都可以正常工作,但在 CentOS 6.8 的客户端 PROD 环境中却无法正常工作。 It is also working fine on Client UAT environment with CentOS 6.5.它在 CentOS 6.5 的客户端 UAT 环境中也能正常工作。

The code creates executable sh file on the application server and executes it.该代码在应用服务器上创建可执行的 sh 文件并执行它。 sh file contained commands sqlldr and sqlplus to upload data via batch upload mechanism. .sh 文件包含命令 sqlldr 和 sqlplus 通过批量上传机制上传数据。 When executed successfully, a log file is created with output of execution.成功执行后,会创建一个带有执行输出的日志文件。 Any errors like are written in the log file.任何类似的错误都写在日志文件中。 When sh file is not executed, log file is also not created.不执行 sh 文件时,也不会创建日志文件。 When executed manually from terminal, sh file is executed and log file is also created.从终端手动执行时,会执行 sh 文件并创建日志文件。 Below are the contents of sh file下面是sh文件的内容

sqlldr user/pass@db CONTROL=CTL_1000004453.ctl silent=all
echo -e "UPDATE QT_BATCH_UPLOAD SET UPLOAD_STATUS = 20 WHERE UPLOAD_ID = 1000004453;
commit;
exit;
" > SET_STATUS_1000004453.SQL
sqlplus user/pass@db @SET_STATUS_1000004453.SQL

No error is getting obtained in application and server logs.在应用程序和服务器日志中没有获得错误。 Application is running on Weblogic server.应用程序正在 Weblogic 服务器上运行。 I have checked and eradicated all permission related issues.我已经检查并消除了所有与许可相关的问题。

Please help if anyone has encountered such non-replicating issue ever.如果有人遇到过这种非复制性问题,请提供帮助。

Below is the code.下面是代码。

        try
        {

          Runtime rt = Runtime.getRuntime();
          Process pr = rt.exec(new String[] { "/bin/bash", "-c", "cd " + path + " ;chmod a+x " + exeFile + "; sh " + exeFile + ";" });

          BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream()));

          FileOutputStream file3 = new FileOutputStream(path + "CONSOLE_" + uploadID + ".LOG");
          String line; while ((line = br.readLine()) != null) { String line;
            System.out.println(line);
            file3.write((line + System.getProperty("line.separator")).getBytes());
            file3.flush();
          }
          file3.close();

        }

Issue has been resolved.问题已解决。 No change in code was required.无需更改代码。 Actually the app server (Weblogic) was being run via console.实际上,应用服务器 (Weblogic) 是通过控制台运行的。 I did some R&D and asked the client to run it via putty/terminal, post which, the code ran fine.我做了一些研发,并要求客户通过腻子/终端运行它,发布后,代码运行良好。

I would still look for solutions to get the same working when weblogic runs via console.当 weblogic 通过控制台运行时,我仍然会寻找解决方案来获得相同的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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