Bash – How to execute a bash shell script via a browser link

apache-2.2bashhtmljboss

I have written a bash script that periodically checks a directory for newly added .ear files and copies them to the respective JBoss server's deploy directory.Before copying, it checks if JBoss is running, and stops it if it is.After copying the file,it removes the older .ear files if any,and starts JBoss.
I am trying to have this script executed via a web page. i.e provide a link to the users, clicking on which, the entire process gets executed.So far I am not able to get the desired result, though manually executing it works.
I'm getting the following error in http logs:

warn] [client 127.0.0.1] Timeout waiting for output from CGI script /var/www/cgi-bin/auto.sh, referer: http://localhost/

Would appreciate if someone could shed some light on how to go about it.

Best Answer

  1. The CGI script will run with the userid of the webserver, which might not be the userid of the person who was testing it. Have you considered that?

  2. The CGI script needs to print a header and some output like "Success, thanks for using auto.sh".

 echo "Content-type: text/plain"
 echo 
 echo "Success, thanks for using auto.sh"

If its too clunky trying to do CGI from the shell, wrap it in a little bit of perl or python which have libraries to deal with CGI.

An alternative approach would be to leave a token in a file or database column that tells it to run, and then have it either activate from cron or have it constantly run and look for the token.

Also, depending on how the web server is set up, your CGI only gets so long to run before it times out...