Running
ping from apache webserver using CGI
Main
Tasks
1.Setup
Apache webserver
2.
Create script
3.
Run from browser
1.1
Setup apache webserver
yum
install http
d
1.2
Start the service
service
httpd start
1.3
Add init.d for server to come up automatically after reboot
chkconfig
--add httpd
chkconfig
httpd on
1.4
To get CGI directoy from httpd.conf
grep
cgi /etc/httpd/conf/httpd.conf
Usually
it will be at "/var/www/cgi-bin"
2.
Create shell script at CGI home
2.1 Got cgi-bin folder
cd
/var/www/cgi-bin
2.2 Create shell script /CGI at this location .
vi
serverping.cgi
Get file from github , source is menstion in the top
* it will create a output file based on time :
FILENAME=/tmp/cgi`date +%m%d%Y_%H%M%S`
* it will read through hostlist.txt , it contains
hostname , IP and other details , script
will read only first part
: echo $LINE | cut -f1 -d" " > /tmp/hosts
* it will call pingserver.sh For each valid IP
* Depending up on the result , it will append
in the FILENAME
* Finally result will displayed
echo
"<pre>"
cat
$FILENAME
echo
"</pre>"
2.3 Create hostlist.txt
vi hostlist.txt
2.4 Create pingserver.sh
vi
pingserver.sh
* it will use ping
-c1 -W1 -q . this
most efficient way to get the output from ping
* If status is 0 , then server is UP
2.5 Before running script from browser , cgi file can be run as shell
script to test the output
./serverping.cgi
3 . Run from browser :
URL will be
http://IP/cgi-bin/serverping.cgi
No comments:
Post a Comment