views:

89

answers:

2

First and foremost I should acknowledge that I have no experience at all using Java ServerPages, but I'm positive about achieving this task if you guys help me out a bit since it doesn't seem like something difficult for a seasoned JSP programmer.

Anyway the thing is, there's an actual running JSP application within a *NIX box which I somewhat administer with kind of good permissions. The idea is to create a new but dead simple JSP page to control some Korn Shell scripts I've got running there. So the goal is to make some sort of HTML form that will be writing some kind of scriptStatus.on / scriptStatus.off file:

#!usr/bin/ksh
# coolScript.sh
# This is my cool script that is being launched by cron every 10 minutes.

if [ -e scriptStatus.off ]
  then 
      # monitor disabled
  else
      # monitor enabled
fi

which then can be checked for existence within the running script, therefore allowing to easily activate / deactivate it without actually have do deal with cron. Please let me know if all this does make any sense and don't hesitate to ask as much questions as needed.

Thanks much in advance!

+2  A: 

You may have security issues here. Consider what risks you have and take appropriate steps to authenticate users and ensure they are authorized for this operation. The steps necessary for this depend to some extent on the servlet container you are using.

You don't need a library like Apache Commons IO for a such simple task. File.createNewFile and File.delete could be used if you are not concerned about a race condition between two different users.

File flag = new File("/path/scriptStatus.off");
String message;
if (flag.delete())
  message = "Script enabled.";
else if (flag.createNewFile()) 
  message = "Script disabled.";
else
  /* Maybe missing directory, wrong permissions, race condition. */
  message = "Error: script state unknown.";

A cron job can check to see whether the (empty) file exists or not, and act accordingly.

erickson
Thanks much for your reply! It's been really informative. Would you mind elaborating a bit about how to pass a form variable to such code so i can trigger that code using HTML form controls?
Nano Taboada