tags:

views:

932

answers:

2

My web page uploads a file. Currently it places that file in a directory which is polled by a cron job. If the file is there, a bash script acts on the file. I hate the fact that I am polling. The upload happens perhaps once a week, but the user wants to see results within minutes from their file, so I end up polling every 5 minutes.

So rather than polling, I'd like to evoke the script once the upload is complete. How can I get my web page to fire up the bash script. The web page is coded with JSP.

+3  A: 

So long as you haven't got a SecurityManager set, you can use Runtime.exec to call an executable program. In particular you can run /bin/bash (or whatever path it is to your shell). Note the -c option for shells.

As LFSR points out, this is the sort of thing likely to be full of security flaws.

Tom Hawtin - tackline
SecurityManager?
dacracot
java.lang.SecurityManager. Not very fashionable. Mostly used for applets and WebStart.
Tom Hawtin - tackline
A: 

Why don't you do this from your app? It won't be very hard to implement an FTP client in Java. Surely there are open/free libraries to accomplish this somewhere. I don't believe this script does anything that you can't do in Java. A message driven bean with the FTP code should be enough. Your server is not FTP? Well, installing FTP isn't that hard either.

Ubersoldat
The script does more than we are willing to write in Java. Not because Java can't, but one line in bash to do a rsync using a dsa/rsa link would take considerable effort to replicate in Java.
dacracot