码迷,mamicode.com
首页 > Web开发 > 详细

Linux环境下使用shell编写CGI(httpd)

时间:2015-07-18 10:53:34      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:

/var/www/cgi-bin/hello.sh

技术分享
#!/bin/bash

echo "Content-type: text/html"
echo ""

echo <html>
echo <head>
echo <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
echo <title>Hello World</title>
echo </head>
echo <body>
echo Hello World
echo </body>
echo </html>

exit 0
        
View Code

赋予执行权限:

chmod +x /var/www/cgi-bin/hello.sh

如果使用SELinux,必须执行以下命令: chcon -t httpd_sys_content_t /var/www/cgi-bin/hello.sh

访问:

http://ip/cgi-bin/hello.sh

同理:

/var/www/cgi-bin/uptime.sh

技术分享
#!/bin/bash

echo "Content-type: text/html"
echo ""

echo <html>
echo <head>
echo <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
echo <link rel="SHORTCUT ICON" href="http://www.megacorp.com/favicon.ico">
echo <link rel="stylesheet" href="http://www.megacorp.com/style.css" type="text/css">

PATH="/bin:/usr/bin:/usr/ucb:/usr/opt/bin"
export $PATH

echo <title>System Uptime</title>
echo </head>
echo <body>

echo <h3>
hostname
echo </h3>

uptime

echo </body>
echo </html>

exit 0
View Code

http://192.168.1.112/cgi-bin/uptime.sh

 

/var/www/cgi-bin/env.sh

技术分享
#!/bin/bash

echo "Content-type: text/html"
echo ""

echo <html>
echo <head>
echo <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
echo <title>Environment Variables</title>
echo </head>
echo <body>
echo Environment Variables:
echo <pre>
/usr/bin/env
echo </pre>

echo </body>
echo </html>

exit 0
        
View Code

http://192.168.1.112/cgi-bin/env.sh?namex=valuex&namey=valuey&namez=valuez

参考:

http://www.yolinux.com/TUTORIALS/BashShellCgi.html

 

Linux环境下使用shell编写CGI(httpd)

标签:

原文地址:http://www.cnblogs.com/super-d2/p/4656284.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!