Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Running Linux shell scripts from JSP  RSS feed

 
J Pleau
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am looking to write a JSP for internal use in my office that would automate some tasks that are commonly run from the command line. In order to make the tasks easier for users, I want to set them up using HTML forms for the parameters and then click to run instead of incredibly long command lines.
Here's the dilemna:
1) How do I run shell scripts from within a JSP? Do I use java.lang.runtime?
2) How can I run the script so that it is as a specific user (for file creation) - should I just 'su' to that user within the script or can I set the user in the JSP?
3) Some of these tasks take hours to complete, I would like to know if it's possible to run these in the background so that users could close the browser after inititating the scipt.
Hope you can help
JP
 
norman richards
Author
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runtime.exec() will execute the scripts.
To make the scripts run as a given user, you could change the owner of the scripts and make them SUID. (chmod +s) I don't recommend this for a shell script. For security reasons, you should probably be executing a SUID wrapper executable written in C that will invoke your shell script. But if you aren't concerned with security on that box (you are only concerned about security from outside the box) it doesn't matter much.
With java, pure background (run and ignore) processes aren't really practical. It would be better to have a wrapper around it that launches the real script in the background and redirects stdin/stdout to /dev/null.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mind that many application servers prevent the execution of external processes by JSP, Servlet, CGI, etc. etc. for security reasons so it may very well not be possible at all.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!