Sponsored Content
Top Forums Shell Programming and Scripting calling unix script from JSP??? Post 302075812 by Bhups on Wednesday 7th of June 2006 02:39:25 AM
Old 06-07-2006
Question calling unix script from JSP???

Hi all,

i have requirement where i need to call a unix script from a JSP code. my script should list all the csv files from a directory and then should upload the file names to an oracle table (using sqlloader).

i tried using getRuntime function in JAVA to call my script and was successfully able to list all the files in that directory. but the issue i am facing is that when i added a filter of listing only csv files (ls *csv* > tempfile) then also its listing all teh files (and not only teh csv files).

one more issue here is that i have to give teh entire path of list command (/usr/bin/ls) and hence have to give path for each and every command i use further in teh script (i just tried the functionality of calling a script from JSP and then listing all files). the issue here i feel is that the unix shell is not being spawned here and thats why the basic commands are not available to teh code.

so basically teh script is not working at all Smilie .....please help!!!!

the code i used is mentioned below:

helloworldapp.java:
==========

import utility.ErrorPage;
import utility.ConnectionPool;
import utility.GeneralSecurity;
import utility.ErrorClass;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.util.*;


public class HelloWorldApp extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException ,IOException
{
PrintWriter out = res.getWriter();
try
{
res.setContentType("text/html");
out.print("<HTML><HEAD><TITLE>Testing Servlets</TITLE></HEAD><BODY><H1>Hello World</H1>");
java.lang.Runtime rt = java.lang.Runtime.getRuntime();
out.println("Before Executing script file");

//String scriptfile="ls >> temp1234.txt";
//String scriptfile="HelloWorldApp.sh";
//String process1=scriptfile;
//Process child = rt.exec("/bin/ksh");
//Process child = rt.getRuntime().exec("/usr/bin/ksh");
//child.waitFor();
//int exitValue1=child.exitValue();
//out.println("The Return Value of ksh : "+exitValue1);

Process p1 = rt.getRuntime().exec("/home/user/HelloWorldApp.sh");
p1.waitFor();
int exitValue=p1.exitValue();
out.println("The Process to be executed is : ");
out.println("The Return Value : "+exitValue);
out.print("</BODY></HTML>");
out.close();
}
catch(Exception excpUser)
{
out.println(excpUser.getMessage());
}

}
}

shell script:HelloWorldApp.sh:
===========

#!/bin/ksh

. $HOME/.profile

/usr/bin/ls > /home/user/temp1234.txt
#/usr/bin/cat temp1234.txt | /usr/bin/grep *csv* > temp1234.txt


sorry for the lengthy mail Smilie

regards,
Bhups.
 

10 More Discussions You Might Find Interesting

1. Programming

calling UNIX script from C/C++

Hi all, Is it possible to call a UNIX script from C/C++ program? If yes, can you please tell me how? Thank you in advance Regards (3 Replies)
Discussion started by: omran
3 Replies

2. Shell Programming and Scripting

Help with shell script - Unix Gurus calling

Unix Gurus, I have been breaking my head to get this done..seems simple.. I need to read a flat file and based on a key word in a line, i need to skip the previous 3 lines. eg : Line1 Line2 Line3 Line4 Line5 Line6 Error Line7 Line8 Line9 Error Line10 (4 Replies)
Discussion started by: ravred
4 Replies

3. UNIX for Advanced & Expert Users

calling plsql function in a unix script

Could anyone please help me. I have a function in plsql that returns a number. But i am listing some records through that function using DBMS_OUTPUT.PUT_LINE. I want to catch those records by executing this function through a unix script. The following shows what i did echo "Connected from... (2 Replies)
Discussion started by: cobroraj
2 Replies

4. Shell Programming and Scripting

Can we call JSP file from Unix.if so how.Please help me.Im newbie to Unix

Hi Can we call a jsp page from Unix.if so please let me know how we can.. thanks for the help in advance... thanks kumar (0 Replies)
Discussion started by: mailsukumar
0 Replies

5. UNIX for Advanced & Expert Users

Calling unix script from sql or plsql

Hi Can anyone please let me know how to call unix scripts from sql or plsql ASAP. (2 Replies)
Discussion started by: ksailesh
2 Replies

6. Shell Programming and Scripting

Calling a request set from Unix shell Script

Hi All, I want to call a concurrent request set from a shell script. I am getting the syntax error "syntax error at line 417 : `(' unexpected" in the below script. v_request_id=fnd_request.submit_request(application => 'APPL_SHORT_NAME' ,program => 'PROGRAM_SHORT_NAME' ... (4 Replies)
Discussion started by: swatipevekar
4 Replies

7. Shell Programming and Scripting

Running a unix script(which is calling another script inside that) in background

Hi all, I am having a script ScriptA which is calling a script ScriptB in the same server and copying files to second server and have to execute one script ScriptC in the second server. THis First script ScriptA is the main script and i have to execute this process continously. for Keeping... (2 Replies)
Discussion started by: rohithji
2 Replies

8. Shell Programming and Scripting

Calling Java Method from UNIX using shell script

Hi All, I need to call a java method from a shell script. I know we can use the command java ClassName to call the main method in it. But I need to call another method that is there in the class and pass an email to it. Can I use java ClassName.MethodName(email) Any help will be... (4 Replies)
Discussion started by: RahulK
4 Replies

9. UNIX for Dummies Questions & Answers

calling a unix shell script from sqlplus

I want to execute a shell script from sqlplus prompt and get its output back to sqlplus. Is this possible? if yes just give me an example for doing that. (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

10. Shell Programming and Scripting

Calling another Script from Command Line in UNIX

Hi all, I am having problem in understanding the following line of code .. /home/rmsbatch/autoscript/autorms.ksh dc_load_main.ksh -q belk_dc_load_tran_data.seq What's being done here ? what does "-q" means ? What does ".seq" file means in unix "belk_dc_load_tran_data.seq" Please... (3 Replies)
Discussion started by: LoneRanger
3 Replies
Tcl_AllowExceptions(3)					      Tcl Library Procedures					    Tcl_AllowExceptions(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_AllowExceptions - allow all exceptions in next script evaluation SYNOPSIS
#include <tcl.h> Tcl_AllowExceptions(interp) ARGUMENTS
Tcl_Interp *interp (in) Interpreter in which script will be evaluated. _________________________________________________________________ DESCRIPTION
If a script is evaluated at top-level (i.e. no other scripts are pending evaluation when the script is invoked), and if the script termi- nates with a completion code other than TCL_OK, TCL_ERROR or TCL_RETURN, then Tcl normally converts this into a TCL_ERROR return with an appropriate message. The particular script evaluation procedures of Tcl that act in the manner are Tcl_EvalObjEx, Tcl_EvalObjv, Tcl_Eval, Tcl_EvalEx, Tcl_GlobalEval, Tcl_GlobalEvalObj, Tcl_VarEval and Tcl_VarEvalVA. However, if Tcl_AllowExceptions is invoked immediately before calling one of those a procedures, then arbitrary completion codes are per- mitted from the script, and they are returned without modification. This is useful in cases where the caller can deal with exceptions such as TCL_BREAK or TCL_CONTINUE in a meaningful way. KEYWORDS
continue, break, exception, interpreter Tcl 7.4 Tcl_AllowExceptions(3)
All times are GMT -4. The time now is 05:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy