Knowledge Base Article

How to run simple shell scripts directly from a browser?

To be able to run shell scripts directly from the browser, you should add this rule to your .htaccess file:

Options ExecCGI
AddHandler cgi-script .sh


This tells the webserver to treat .sh files as CGI scripts.

 

To test this, let's try printing today's date in your browser. To do this, create a file called date.sh with the following content:

 

 

#!/bin/bash
DATE="$(date)"
echo "Content-type: text/html"
echo ""
echo "<html><head><title>Test</title></head><body>"
echo "Today is $DATE <br>"

 

Save the file and change its permissions to 755.

 

Now open www.yourdomain.com/date.sh and the output you get should be similar to this:

 

Today is Wed Jan 21 09:01:38 CST 2009



Rating

Please indicate if this article was helpful for you.

rating :  4.7 from 5
views :  3433
votes :  22

Haven't found what you are looking for? Suggest an article HERE.

powered by

Valid XHTML 1.0 Strict Valid CSS!