Run linux commands through webpage

Posted on Updated on

You my use webinterface to run some bash scripts through you can watch system process and some other things, Lets watch how to do.

CGI support with apache / httpd webserver

$/var/www/cgi-bin
$vi desktop1.cgi

desktop1.cgi code listing:

#!/bin/bash
echo “Content-type: text/html”
echo “”
echo “<html><head><title>Bash as CGI”
echo “</title></head><body>”
echo “<h1>General system information for host $(hostname -s)</h1>”
echo “”
echo “<h1>Memory Info</h1>”
echo “<pre> $(free -m) </pre>”
echo “<h1>Disk Info:</h1>”
echo “<pre> $(df -h) </pre>”
echo “<h1>Logged in user</h1>”
echo “<pre> $(w) </pre>”
echo “<center>Information generated on $(date)</center>”
echo “</body></html>”

Change file permission to execute :

$chmod +X desktop1.cgi

Open your browser and check like this http://Your.server.ip/cgi-bin/disktop1.cgi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s