You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by abhisheks <sa...@gmail.com> on 2012/02/03 04:53:47 UTC

calling shell script from Wicket java program

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 !! 


--
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: calling shell script from Wicket java program

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Sat, Feb 4, 2012 at 4:56 AM, Martin Grigorov <mg...@apache.org>wrote:

> On Fri, Feb 3, 2012 at 5:53 AM, abhisheks <sa...@gmail.com> 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*

Re: calling shell script from Wicket java program

Posted by Martin Grigorov <mg...@apache.org>.
On Fri, Feb 3, 2012 at 5:53 AM, abhisheks <sa...@gmail.com> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



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

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org