Quantcast

calling shell script from Wicket java program

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

calling shell script from Wicket java program

abhisheks
i am developing a web application using apache wickets. I need to call a shell script residing on my local disk from java code.

this is the section of code under concern :

ProcessBuilder builder = new ProcessBuilder("sh","/media/drive_/MtechDocuments/ProgramingNOTES/RunShellfromJAVA/test.sh");
                    builder.redirectErrorStream(true);
                       final Process process = builder.start();
                   }                      
                                 process.waitFor();

------

This is piece of code successfully runs fine and execute a shell when this code is a part of java prgram residing anywhere on my laal disk. However, when i make a jar file of a progeam , put in webapps folder , and start the web application , it reports permission denied error on test.sh script.

I then modify the line as :

ProcessBuilder builder = new ProcessBuilder("sudo", "-A", "sh","/media/drive_/MtechDocuments/ProgramingNOTES/RunShellfromJAVA/test.sh");
and set the SUDO_ASKPASS env variable to script returning my sudo password , then it reports the following error :
sudo: 3 incorrect password attempts and script calling is failed. Again this works correctly when i run the program outside the web development environment , it is able to read my sudo password correctly at run time with -A option. Why is it failing when running the same program from web application ?  please help !!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: calling shell script from Wicket java program

Martin Grigorov-4
On Fri, Feb 3, 2012 at 5:53 AM, abhisheks <[hidden email]> wrote:

> i am developing a web application using apache wickets. I need to call a
> shell script residing on my local disk from java code.
>
> this is the section of code under concern :
>
> ProcessBuilder builder = new
> ProcessBuilder("sh","/media/drive_/MtechDocuments/ProgramingNOTES/RunShellfromJAVA/test.sh");
>                                 builder.redirectErrorStream(true);
>                                    final Process process = builder.start();
>                        }
>                                 process.waitFor();
>
> ------
>
> This is piece of code successfully runs fine and execute a shell when this
> code is a part of java prgram residing anywhere on my laal disk. However,
> when i make a jar file of a progeam , put in webapps folder , and start the
> web application , it reports permission denied error on test.sh script.
>
> I then modify the line as :
>
> ProcessBuilder builder = new ProcessBuilder("sudo", "-A",
> "sh","/media/drive_/MtechDocuments/ProgramingNOTES/RunShellfromJAVA/test.sh");
> and set the SUDO_ASKPASS env variable to script returning my sudo password ,
> then it reports the following error :
> sudo: 3 incorrect password attempts and script calling is failed. Again this
> works correctly when i run the program outside the web development
> environment , it is able to read my sudo password correctly at run time with
> -A option. Why is it failing when running the same program from web
> application ?  please help !!

Maybe your web server runs with a user which has no permissions to
become different user (via sudo).
When you run it as a normal Java program you run it with your user
which has this permission.

In any case it has nothing to do with Wicket.

>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/calling-shell-script-from-Wicket-java-program-tp4353583p4353583.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>



--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: calling shell script from Wicket java program

jeremy@wickettraining.com
On Sat, Feb 4, 2012 at 4:56 AM, Martin Grigorov <[hidden email]>wrote:

> On Fri, Feb 3, 2012 at 5:53 AM, abhisheks <[hidden email]> wrote:
> > i am developing a web application using apache wickets. I need to call a
> > shell script residing on my local disk from java code.
> >
> > this is the section of code under concern :
> >
> > ProcessBuilder builder = new
> >
> ProcessBuilder("sh","/media/drive_/MtechDocuments/ProgramingNOTES/RunShellfromJAVA/test.sh");
> >                                 builder.redirectErrorStream(true);
> >                                    final Process process =
> builder.start();
> >                        }
> >                                 process.waitFor();
> >
> > ------
> >
> > This is piece of code successfully runs fine and execute a shell when
> this
> > code is a part of java prgram residing anywhere on my laal disk. However,
> > when i make a jar file of a progeam , put in webapps folder , and start
> the
> > web application , it reports permission denied error on test.sh script.
> >
> > I then modify the line as :
> >
> > ProcessBuilder builder = new ProcessBuilder("sudo", "-A",
> >
> "sh","/media/drive_/MtechDocuments/ProgramingNOTES/RunShellfromJAVA/test.sh");
> > and set the SUDO_ASKPASS env variable to script returning my sudo
> password ,
> > then it reports the following error :
> > sudo: 3 incorrect password attempts and script calling is failed. Again
> this
> > works correctly when i run the program outside the web development
> > environment , it is able to read my sudo password correctly at run time
> with
> > -A option. Why is it failing when running the same program from web
> > application ?  please help !!
>
> Maybe your web server runs with a user which has no permissions to
> become different user (via sudo).
> When you run it as a normal Java program you run it with your user
> which has this permission.
>
> In any case it has nothing to do with Wicket.
>

And if your webapp *is* running as a user with sudo access you're just
asking for trouble.

--
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*
Loading...