• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Running Linux shell scripts from JSP

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic