Executing sudo linux commands through a JSP page.

Hi,
I need to execute some superuser commands through a JSP page under Linux.
I added users apache and tomcat to the /etc/sudoers file with no password prompting.
My JSP page works fine with any usual linux command, but when I call a “sudo cmd” I have a message (when reading the ErrorStream instead of the InputStream) that “sudo can’t be executed because it needs a tty” even when I call the shell before the sudo command.
Here is a piece of my code (very basic):
String cmd="linux_cmd";
Process proc = Runtime.getRuntime().exec(cmd);
InputStream stdin = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(stdin);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ( (line = br.readLine()) != null)
out.println(line);
Is there any way I can make sudo calls from a JSP page ?
I know that making root calls from a web application is a bad thing, but for now security is not my concern.
Thank you for any tips.

JavaFan2 wrote:
In fact, I help supervising a student project who is supposed to write an admin application to offert graphical interfaces for some security and system tools under Linux (like fdisk, iptables etc) using J2EE, ... something like Webmin.
As I said, I know that is has a huge security risk but this app has the only purpose of learning J2EE, no security issues are treated.If you want to say "I will leave my office door open because there's no security risk in doing that" then that's a valid statement. But what you are trying to do here isn't the equivalent of leaving your office door open. It's the equivalent of finding a master key for all the offices in the world. And as such it is in fact a serious security risk which should not be circumvented.
And no, it's no good saying "But I'm only going to use this all-powerful master key to open my own office door". If you get the key then anybody else can get the key too.

Similar Messages

  • Executing a linux command through flash lite

    Hello All,
    i want to know one thing.. : is it possible to execute a linux command through flash lite?
    I mean, say, in linux at the command prompt if i want to change the date and time then i will execute command date 082110452009.00 to set
    21 August 2009, 11:45:00 .. i want to do this through actionscript2.. first i wil provide a UI asking the user to set date, time, year.. once he clicks OK i want to execute the above command with the user input..
    This is because currently i m running this application on an embedded linux device which doesn't have a real time clock.. i mean once i switch off and ON the device the date and time will set back to default value 01 Jan 1970 as it happens in linux..
    any suggestions?

    get the the inputStream of the runtime object after executing the command.
    now use the readLine() function until it becomes null.
    egs: with reference to ur code.
    InputStream is=p.getInputStream()
    while(is!=null)
    String s=is.readLine();
    if the command don't execute try giving the full path also like /sbin/ls -l

  • Executing a shell script from a jsp page

    Hi,
    I'm facing a problem while executing a shell script from a jsp page.
    I'm using Runtime.exec() function.
    It's working fine for single statement scripts.But if the script consists of any database processing and some other processing statements,it's not returning the correct exit status of the process.
    Will u please help me in this.
    If there is any other ways to execute a shell script from a jsp page other than Runtime.exec() like RMI etc,.If so let me know.
    Thanks in advance.

    Hello,
    It's hard to help you but what you can do is listening to the outputs of your script, you should read the output stream and error stream and send them to the default console.
    Check this excellent article : http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4
    Best regards,
    Olivier.

  • Executing the top command through Java in linux

    I am trying to execute the top command in Java as
    Runtime.getRuntime().exec("top -n 1 >a.log");
    But the command is not working in linux only through java.When i run the same command through the prompt it is working fine.Also all other commands are working fine.Is there any issue with top in linux?

    flounder wrote:
    Try reading [this article|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html]. If it does not answer your problem then try seaching for other similar articles.
    The cited article does provide an answer to the problem since it explains how the shell meta character '>' must be interpretted by a shell. The code as presented does not invoke a shell.

  • Problem in executing a unix command through java

    hi
    i'm trying to execute unix command through java
    simple shell command like "ls -l >test " but i'm not able to see the result.
    there are no error messages.
    Code is:
    import java.lang.Runtime.*;
    class ExecDemo
         public static void main(String[] args)
              Runtime r=Runtime.getRuntime();
              Process p=null;
              try
                   p=r.exec("ls -l > test");
              catch (Exception e)
                   System.out.println("Error executing nedit.");
    }can anyone help please.

    get the the inputStream of the runtime object after executing the command.
    now use the readLine() function until it becomes null.
    egs: with reference to ur code.
    InputStream is=p.getInputStream()
    while(is!=null)
    String s=is.readLine();
    if the command don't execute try giving the full path also like /sbin/ls -l

  • How to execute MS DOS command through Java program???

    Dear Sir,
    I want to run a MS-DOS command through my Java program. I have tried "Dir" command but no other command which takes command line args doesn't work at all. Please help.
    import java.io.*;
    class CommandPrompt
         public static void main(String[] args)
              try
                   File file = new File("C:/Temp/Java");
                   String[] cmd = {"command.com","/c","md folder"};
                   String[] envp = {""};
                   Process m;
                   String s = "";
                   m = Runtime.getRuntime().exec(cmd,null,file);
                   BufferedReader buf = new BufferedReader(new InputStreamReader(m.getInputStream()));
                   while ((s = buf.readLine())!=null)
                        System.out.println(s);
              catch (Exception ex)
                   System.out.println("Exception is "+ex);
                   ex.printStackTrace();

    1. This forum is for Swing-related issues only. This question should be posted to the "Java Programming" forum.
    2. Please enclose your sample code in code blocks; it's much easier to read that way. See here for how it's done: http://forum.java.sun.com/faq.jsp#messageformat
    3. Please provide more information, like what error messages you got and what OS you're running. For instance, if you're running WinXP, Win2k or NT4, your command processor should be "cmd.exe", not "command.com". When I made that change, your program worked for me.

  • How to generate report in pdf format through a JSP page

    I require to generate my report from my JSP page into a PDF format . How can i do it?

    Use a Java API which can create PDF files based on some collection of plain vanilla Java objects (List, String, Number, etc).
    Google can find them all. Just feed it with something like "Java PDF API" or so. A commonly used one is iText.
    That said, when talking about this in JSP context, ensure that you do NOT write raw Java code in JSP files using scriptlets. Raw Java code belongs in Java classes. In such case you need a Servlet. In JSP just use taglibs and EL to interact with backend Java code and data. Scriptlets are discouraged since over a decade.

  • Passing values at run time through a JSP page to selection formula to crystal report

    <p>hi,</p><p>   i am using one jsp page.in that page there is a field to select a date </p><p>this value will go to the report and report contain one selection formula.</p><p>which value we are passing on that basis the report should display</p><p>with date which we are passing  from GUI.</p><p>help.............................................................</p><p>//R</p>

    I believe the value of this is based on the owner of the scheduled object.  So if the Admin is scheduling it on behalf of a user I think it should use the user the Admin scheduled on behalf of.  It should be simple to test, simply create a report with this value being displayed and nothing else and see what values you get.

  • Is it possible to execute OS level commands through Oracle APEX?

    Hi,
    I would like to know if it is possible to execute OS level commands, say executing any command in command prompt using Oracle APEX.
    Thanks!

    Welcome to Oracle Forums!
    Please acquaint yourself with the FAQ and forum etiquette if you haven't already done so.
    Always state
    <ul>
    <li>Apex Version</li>
    <li>DB Version and edition</li>
    <li>Web server used.I.e. EPG, OHS, ApexListner Standalone or with J2EE container</li>
    <li>When asking about forms always state tabular form if it is a tabular form</li>
    <li>When asking about reports always state Classic / IR</li>
    <li>Always post code snippets enclosed in a pair of &#123;code&#125; tags as explained in FAQ</li>
    </ul>
    I would like to know if it is possible to execute OS level commands, say executing any command in command prompt using Oracle APEX.If by OS you are referring to the client side, then NO.
    Cheers,

  • PROBLEM in executing a shell command through Runtime.getRuntime().exec()

    Hi all,
    I was trying to execute the following code:
    import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.Statement;
    import java.sql.ResultSet;
    * Created on Mar 13, 2007
    * To change the template for this generated file go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    * @author 195092
    * To change the template for this generated type comment go to
    * Window>Preferences>Java>Code Generation>Code and Comments
    public class ClassReportDeleteDaemon {
         ClassReportDeleteDaemon()
         public static void main(String[] args) throws Exception
              Connection conn = null;
              Statement stmt = null;
              ResultSet rs;
              String strQuery = null;
              String strdaysback = null;
              String delstring = null;
              int daysback;
              try
                   System.out.println("REPORT DELETION ::: FINDING DRIVER");               
                   Class.forName("oracle.jdbc.driver.OracleDriver");
              catch(Exception e)
                   System.out.println("REPORT DELETION ::: DRIVER EXCEPTION--" + e.getMessage());
                   System.out.println("REPORT DELETION ::: DRIVER NOT FOUND");
              try
                   String strUrl = "jdbc:Oracle:thin:" + args[0] + "/" + args[1] + "@" + args[2];
                   System.out.println("REPORT DELETION ::: TRYING FOR JDBC CONNECTION");
                   conn = DriverManager.getConnection(strUrl);
                   System.out.println("REPORT DELETION ::: SUCCESSFUL CONNECTION");
                   while(true)
                        System.out.println("WHILE LOOP");
                        stmt = conn.createStatement();
                        strQuery = "SELECT REP_DAYS_OLD FROM T_REPORT_DEL";
                        rs = stmt.executeQuery(strQuery);
                        while(rs.next())
                             strdaysback = rs.getString("REP_DAYS_OLD");
                             //daysback = Integer.parseInt(strdaysback);
                        System.out.print("NO of Days===>" + strdaysback);
                        delstring = "find /tmp/reports1 -name " + "\"" + "*" + "\"" + " -mtime +" + strdaysback + " -print|xargs rm -r";
                        System.out.println("DELETE STRING===>" + delstring);
                        Process proc = Runtime.getRuntime().exec(delstring);
                        //Get error stream to display error messages encountered during execution of command
                        InputStream errStream=proc.getErrorStream();
                        //Get error stream to display output messages encountered during execution of command
                        InputStream inStream = proc.getInputStream();
                        InputStreamReader strReader = new InputStreamReader(errStream);
                        BufferedReader br = new BufferedReader(strReader);
                        String strLine = null;
                        while((strLine=br.readLine())!=null)
                             System.out.println(strLine);
                   }     //end of while loop
              }     //end of try
              catch (Exception e)
                   System.out.println("REPORT DELETION ::: EXCEPTION---" + e.getMessage());
                   conn.close();
         }     //end of main
    }     //end of ClassReportDeleteDaemon
    But it is giving the error "BAD OPTION -print|xargs". The command run well in shell.
    Please help.
    Thanking u.......

    Since the pipe '|' is interpreted by the shell then you need the shell to invoke your command
            String[] command = {"sh","-c","find /tmp/reports1 -name " + "\"" + "*" + "\"" + " -mtime +" + strdaysback + " -print|xargs rm -r"};
            final Process process = Runtime.getRuntime().exec(command);
      You should also read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html at least twice and implement the recommendation regarding stdout and stderr.
    P.S. Why are you not using Java to find and delete these files?
    Message was edited by:
    sabre150

  • How to Access the Remote Servlet through a JSP Page

    Hi ,
    I wrote a servlet in my local system and It is running very well in my tomcat server5.5. Now I write a JSP code an another one system. Now I don't know how to call my servlet when Click a submit button. I need a small example or idea about this. Help me
    Thanks in advance,
    Maheshwaran Devaraj

    Just like any other servlet or form-processing script. What would a mere HTML page know about "systems"? Put the URL into the form destination attribute and be done.

  • Problem in executing a javascript link on a jsp page

    I am having a problem in executing a javascript function from a link. For example if i click some link let say Discover and behind the scene some applet method is supposed to be called, but it is not called? However the the function name comes in the url area (address bar of internet explorer) like javascript:document.switchApplet.discover()
    Can anybody help me solving this problem?
    Moreover, just for a hint, i think i have deleted some registery value of such time so that's why it is not working. But i am not sure.

    what is d error u r getting ???
    Is it java script error? yes then u can find the line no.
    view the source code or ur page and find whether ur .js is including properly or not? means whether the path is correct ?

  • Sending linux command through labview

    Hi,
    I am using Labview Professional Development system and I have to create a VI that opens a command prompt window to session into a linux based device.
    I have used System Exec to open the window and got to "root-bash#" prompt.
    Question:
    - How do I send command to the linux prompt ? Do I need to buy the labview linux package for Pipe VIs ?

    How about a TCP connection?
    Ctrl-Space (open quick drop) and TCP give me the TCP vis ....
    Greetings from Germany
    Henrik
    LV since v3.1
    “ground” is a convenient fantasy
    '˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'

  • Execute a linux command on java

    Hi i'm trying to execute a c binary on java ,
    the binary is Tcpreplay tool , i tried with the class Runtime but it didn't work plz can any one help me thanks a lot

    ok these are the details
    this is what i tried
    import java.io.* ;
    public class test1
    private static Runtime runtime=Runtime.getRuntime();
    private static Process test ;
    public static void main (String[] args )
    try {
    test=runtime.exec("tcpreplay --intf1=eth1 --intf2=eth2 --cachefile=trace-http.cache trace-http.pcap ") ;
    catch (IOException ex)
    System.out.println("Problem with execution");
    another detail is there is no exception reported

  • Access the files of a web server through a JSP page

    Hello,
    Is it possible to access the files of a an Apache web server, just as you access your local machine.
    Basically i want to access the files of a specific folder, such as http://server:8080/foldername/ ,
    and get a list of all the files stored in there. I know how to do it for the local file system.
    File f = new File(server);
              File files[] = f.listFiles();
              for(int i=0;i<files.length;i++){
              if(files.getName().contains(" ")){
                   System.out.println(files[i].getName());

    This is really dependent on your web server. A web server isn't a shell and the closest equivalent I can think of barring webserver extensions is to configure directory listing to be allowed for the directory you're trying to, grab that html file listing, parse it, and use that to get a list of file names. This is not a very clean solution, so I suspect that whatever problem you're trying to solve, you're going about it the wrong way.
    Assuming Apache: [http://httpd.apache.org/docs/1.3/misc/FAQ.html#indexes|http://httpd.apache.org/docs/1.3/misc/FAQ.html#indexes]

Maybe you are looking for

  • Error in Starting Dispatcher

    When i start my Dispatcher i am getting the following error and it is in Yellow colour. Pls help me in this trc file: "dev_disp", trc level: 1, release: "700" sysno      01 sid        BW7 systemid   560 (PC with Windows NT) relno      7000 patchlevel

  • Remote System Input Device Not Working

    Hi, when i try to connect remote system through RDP, input device (Keyboard & Mouse) in remote system is too slow, it takes more time to respond. Tried to take RDP from different system but same problem. Looking forward for your response.  Regards Mo

  • I have apple tv when i try it used wifi in my computer it didnt work?

    i have apple tv when i try it used wifi in my computer it didnt work? plz help me?

  • How to identify desktop and proff users from user id

    hi all,   I am abaper and new in SRM 4.0. In our project we are implementing customized solution for the confirmation maintainance..it will include ABAP + portal development.we need to implement the same functionality as std SRM is providing. when i

  • How do you consult the management of changing entity?

    Hi Experts, I have a problem with BPC to satisify what the customer wants. It is how BPC handles entity changes including hieararchy and member. It also need to bring data behind of the entity code. So here is three types of entity change. 1. Merge E